Check CheckBox Without Looping

3 posts, 1 answers
  1. Brandy
    Brandy avatar
    4 posts
    Member since:
    Dec 2016

    Posted 05 Mar 2018 Link to this post

    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. Answer
    Dess | Tech Support Engineer, Sr.
    Dess | Tech Support Engineer, Sr.  avatar
    3201 posts

    Posted 06 Mar 2018 Link to this post

    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;
    foreach (GridViewRowInfo row in this.radGridView1.Rows)
        var cellValue = row.Cells["Discontinued"].Value;
        if (cellValue is bool && (bool)cellValue == true)
            row.IsSelected = true;

    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. 
    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.
  3. Brandy
    Brandy avatar
    4 posts
    Member since:
    Dec 2016

    Posted 06 Mar 2018 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    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
Back to Top