This is a migrated thread and some comments may be shown as answers.

Check CheckBox Without Looping

2 Answers 46 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Brandy
Top achievements
Rank 1
Brandy asked on 05 Mar 2018, 06:11 PM
I have a set of data (4000) items that appear in a RadGridView.  The goal is for the user to select items from this GV to save.  When the form re-loads, I need the selected items to automatically show as selected.  
I have that column set as GridViewCheckBoxColumn.

I am looping through the DataClass to match the information in which would determine if the record (row) would be selected.

Since I'm already looping through the data, I dont want to have to loop through the GV each time to find the Cell in which to select.  I was hoping there would be a way to Search or FindBy XXX.

I've yet to find any information on how to do this and it seems like something that most people would use....  What am I missing?

2 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 06 Mar 2018, 12:49 PM
Hello, Brandy,

Thank you for writing.  

If I understand your requirement correctly you want the checked rows (by a certain GridViewCheckBoxColumn) to be marked as selected when setting the DataSource of RadGridView. Looping the Rows collection is the appropriate solution to iterate all data rows and manipulate the selected state for the row when initializing the grid. There is no other suitable solution for handling this synchronization. I would like to note that in order to optimize performance when iterating the rows it is recommended to use the BeginUpdate/EndUpdate block:
this.radGridView1.DataSource = this.productsBindingSource;
 
this.radGridView1.BeginUpdate();
foreach (GridViewRowInfo row in this.radGridView1.Rows)
{
    var cellValue = row.Cells["Discontinued"].Value;
    if (cellValue is bool && (bool)cellValue == true)
    {
        row.IsSelected = true;
    }
}
this.radGridView1.EndUpdate();

However, if it is not the exact requirement please specify in details what is the exact goal that you are trying to achieve. A sample screenshot would be also very useful to get a better understanding of the precise case. Thank you ina dvance. 

I hope this information helps. Should you have further questions I would be glad to help. 
 
 Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Brandy
Top achievements
Rank 1
answered on 06 Mar 2018, 10:43 PM
Yes, that is exactly what I ended up doing.  Minus the  Begin and End Update (which I added)  Thank You.
I have another question on the AddNewRow, but I'll add that in a separate thread.  Thank you
Tags
GridView
Asked by
Brandy
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Brandy
Top achievements
Rank 1
Share this question
or