Hi
I set contextmenuStrip for the ultraGrid.Click the button of the contextmenuStrip to select the ultraGrid all rows.The currnet UltraGrid has the least 5000 data.Then change the selected row in a column of data.Such as: this.UltraGrid.ActiveRow = null; this.UltraGridSelected.Rows.Clear(); for (int i = 0; i < this.UltraGrid.Rows.Count; i++) { this.UltraGrid.Rows[i].Selected = true; }(Or use the foreach,Bind)
if (this.UltraGrid.Selected.Rows.Count > 1) { for (int i = 0; i < this.UltraGridSelected.Rows.Count; i++) { this.UltraGrid.Selected.Rows[i].Cells["Cloumn6"].Value = strProType; } }
But this efficiency is very low,resulting in slow page.There is better way to solve this problem?
Thanks.
The efficeincy is raised to select the ultraGrid all rows.But update slow to selected Grid rows data.
Looping through the rows forces the grid to create UltraGridRow and UltraGridCell objects for every row. There's no way around that.
But if you are updating every row in the grid, why not simply loop through the rows in the data source, instead? That might be faster.
Hi Shankar,
You cannot use the DataSource in this case, since selecting rows is handled by the grid - the data source has no concept of selection. That would only apply to cases where you wanted to remove rows from the grid or do some sort of processing on the row values.
I don't see any way to avoid looping through the grid rows when you want to invert the selection, but you could make sure your code is as efficient as possible.
For example, the code you posted here is accessing the rows collection indexer twice, which is unnecessary. You would be better off using a foreach loop, or at least only getting the row once.
It's also probably best to determine all of the selected rows and then use the AddRange method to select them all at once rather than selecting or deselecting each one individually.
Here's some sample code I whipped up. I tried this with 10,000 rows in a grid and it's practically instantaneous.
private void InvertSelection(UltraGrid grid) { grid.BeginUpdate(); try { List<UltraGridRow> newSelectedRows = new List<UltraGridRow>(); foreach (UltraGridRow row in grid.Rows) { if (false == row.Selected) newSelectedRows.Add(row); } grid.Selected.Rows.Clear(); grid.Selected.Rows.AddRange(newSelectedRows.ToArray()); } finally { grid.EndUpdate(); } }
Hi Mike,
I am trying to select rows from a grid. The link to select rows programatically doesn't work for me since we are providing a invert selection functionality. This functionality requires looping through all records in ultragrid and inverting selection
ie. Grid.Rows[i].Selected = !(Grid.Rows[i].Selected)
This is memory and time consuming operation. Is there a better way to do this. Also you mentioned using the data source instead. I don't understand that. Can you please elaborate on that?
Thanks
Shankar