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

Radio button behaviour for check box

1 Answer 96 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 26 Nov 2007, 06:37 PM
I have a check box field in my grid that I want to be mutually exclussive.  That is, I want only one or zero rows to have a value of true for that check box at any point in time.  I tried code that changes the check box value of every row to false, but this is very slow.  So I thought I would keep a variable that stores the last row index that had a value of true for the check box field.  I have (at least) one group set up for the grid.  I am trying to store the current row index when the grid is first loaded using the following code:
foreach (GridViewRowInfo _row in employeesGrid.Rows)  
{  
    foreach (GridViewRowInfo _row2 in _row.Rows)  
    {  
        if (_row2.Cells["InitialAssignee"].Value != null && (bool)_row2.Cells["InitialAssignee"].Value == true)  
        {  
            curInitialAssignee = employeesGrid.Rows.IndexOf(_row2);  
        }  
    }  
}  
 

This code assumes that there is one level of grouping.  The problem is that curInitialAssignee is always set to -1.  I'm not sure why I can't get the row index of _row2.

Once the above is working, I have code in the ValueChanging event that will set the value of the InitialAssignee column to false for the row that corresponds to curInitialAssignee.  Followed by a line that changes curInitialAssignee to the new current row.

Also, I want to ensure that this row index remains valid even if the data is sorted differently, or a grouping is added or removed at run time.

Thanks,
Eric.

1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 28 Nov 2007, 05:33 PM
Hi Eric,

The reason curInitialAssignee is always set to -1 is that you are assigning the result of employeesGrid.Rows.IndexOf(_row2) instead of the result of _row.Rows.IndexOf(_row2).

I have created a sample project to reproduce your scenario, and I managed to get to the point that you have reached. Unfortunately, it appears that there is no possible way to achieve what you are after, because in the ValueChanging event you need to reset the value of the previously checked row. This causes a refresh of the grid rows, so the new value does not apply to the current row. Refreshing the grid also makes all previous row indices invalid.

I am afraid that I cannot give you any workaround at this time, however there is good news. RadGrdiView is currently under major refactoring and this behavior will not be present in the upcoming version. It is expected to be released in about three weeks. 

I sincerely hope that this timeframe is OK with your project. Let me know if I can be of further assistance.
 

All the best,
Georgi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
GridView
Asked by
Eric
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Share this question
or