Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
290
How to select all cells of a column by code?
posted

Hi,

 

I try to select all cells of a column by code/program like a multi-select would do.

My code looks like this:

        public void SelectColumn(int index)
        {
            foreach (UltraGridRow gridRow in _Grid.Rows)
            {
                if ((gridRow != null) && (gridRow.Cells.Count > index))
                {
                    gridRow.Cells[index].Selected = true;
                }
            }
        }

 

It works fine with about 1.000 rows, but with e.g. 10.000 rows, the performance is poor.
Using Infragistics.Win.UltraWinGrid 11.1

  • 20872
    Offline posted

    Hello Stegerwald,

    We are still following this thread.

    Please feel free to let us know if the suggested approach works for you.

  • 469350
    Suggested Answer
    Offline posted

    Hi,

    You could make this code more efficient in a couple of ways. For one thing, you don't need to check for gridRow != null - the Rows collection iterator should never return null.

    Also, you are checking the cells count in each row, but you could really do this check once rather than on every iteration of the loop.

    Lastly, instead of selecting each cell individually, you could use grid.Selected.Cells.AddRange.


                if (index < this.ultraGrid1.DisplayLayout.Bands[0].Columns.Count)
                {
                    List<UltraGridCell> cells = new List<UltraGridCell>(this.ultraGrid1.Rows.Count);
                    foreach (UltraGridRow gridRow in this.ultraGrid1.Rows)
                    {
                        cells.Add(gridRow.Cells[index]);
                    }

                    this.ultraGrid1.Selected.Cells.AddRange(cells.ToArray());
                }