Hi,
I have a grid for which I've set DisplayLayout.Override.CellClickAction to RowSelect.
I use the DoubleClickRow event to clear the data of the grid, fill the grid with data and then I activate/select the first row:
private void grdData_DoubleClickRow(object sender, Infragistics.Win.UltraWinGrid.DoubleClickRowEventArgs e) { this.dsData.Rows.Clear(); for (int i = 0; i < 10; i++) { UltraDataRow rootRow = this.dsData.Rows.Add(); rootRow["Column 0"] = "1"; rootRow["Column 1"] = "1"; } this.grdData.Rows[0].Activate(); this.grdData.Rows[0].Selected = true; this.grdData.Selected.Rows.Clear(); }
The problem is that the originally selected row gets selected again after grdData_DoubleClickRow() has finished. So I end up with the first row being selected and activated, but also with the originally selected row as selected. So the end result is that two rows are selected instead of one.
When I select a row and use the KeyDown event (using the F5 key in my example), I don't have this issue:
private void grdData_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.F5) { this.dsData.Rows.Clear(); for (int i = 0; i < 10; i++) { UltraDataRow rootRow = this.dsData.Rows.Add(); rootRow["Column 0"] = "1"; rootRow["Column 1"] = "1"; } this.grdData.Rows[0].Activate(); this.grdData.Rows[0].Selected = true; this.grdData.Selected.Rows.Clear(); } }
What could be the problem here?
regards,
Roel van Bueren
The grid responds to the notifications from the DataSource asynchronously. So what probably happens here is that when you clear the data set, the grid doesn't clear it's own rows immediately, it waits for the next paint message.
When you access the Rows collection here, you are still accessing the original rows collection, because the grid has not updated itself, yet.
This is a little odd, because I would think accessing the Rows collection indexer should be forcing the grid to update itself.
But anyway, if I am right, you should be able to get this to work by simply refreshing the grid:
private void grdData_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.F5) { this.dsData.Rows.Clear(); for (int i = 0; i < 10; i++) { UltraDataRow rootRow = this.dsData.Rows.Add(); rootRow["Column 0"] = "1"; rootRow["Column 1"] = "1"; } this.grdData.Refresh() this.grdData.Rows[0].Activate(); this.grdData.Rows[0].Selected = true; this.grdData.Selected.Rows.Clear(); } }
private void grdData_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.F5) { this.dsData.Rows.Clear(); for (int i = 0; i < 10; i++) { UltraDataRow rootRow = this.dsData.Rows.Add(); rootRow["Column 0"] = "1"; rootRow["Column 1"] = "1"; }
this.grdData.Refresh() this.grdData.Rows[0].Activate(); this.grdData.Rows[0].Selected = true; this.grdData.Selected.Rows.Clear(); } }
Hello Mike,
Mike Saltzman"] But anyway, if I am right, you should be able to get this to work by simply refreshing the grid:
I tried that already, but that doesn't work.