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

check GridCheckBoxColumn check box issue.

3 Answers 182 Views
GridView
This is a migrated thread and some comments may be shown as answers.
altaf
Top achievements
Rank 1
altaf asked on 14 Sep 2009, 09:17 AM
hi,

i am getting the issue in check box column whether it is checked or not.
if i use cellformating event then it fires thousands time for one row.

                for (int count = 0; count < grdProductSearch.Rows.Count; count++)
                {
                   string value = grdProductSearch.Rows[count].Cells["Link"].Value.ToString(); //it returns empty value.
                }
if i use this
bool isSelected = grdProductSearch.Rows[count].Cells["ColUniqueName"].CellElement.IsSelected;

then it gives me error that cellelement is null.

Please tell me how i can resolve this issue.

Thanks.

3 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 14 Sep 2009, 02:57 PM
Hi altaf,

CellFormatting fires for every cell when its visual state needs to be update. This includes value change, scrolling, changing the current position or the current column. So, it is normal that this event fires many times. When handling it, you should process only the cell that is in event arguments.

Also, RadGridView uses UI virtualization for its cells. That means that only the visible cells have corresponding cell elements. You should never access the CellElement property outside the CellFormatting event.

To check whether specific row is selected just check its IsSelected property. CurrentCell element contains the current cell and the SelectedCells collection contains all selected cells when MultiSelect mode is on and SelectionMode is set to CellSelect.

However, it is possible that I misunderstood your question. If so, please, describe the exact behavior that you want to achieve. I will be glad to help you further.

Best wishes,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
altaf
Top achievements
Rank 1
answered on 15 Sep 2009, 05:31 AM
Hi Jack,

Thanks for reply.

this line is from your reply.
Also, RadGridView uses UI virtualization for its cells. That means that only the visible cells have corresponding cell elements. You should never access the CellElement property outside the CellFormatting event.

My Scenario and Question is:
I have a RadGridView which has one checkbox column and this grid has different products data.
User select the checkboxes from the grid and click on the "Attach Products" button that is outside the grid then i want to get all the checked checkboxes grid products.
According to your reply we can get the only that cell element which is visible and then can use its property IsSelected, In my case there can be many products in the grid suppose there are 500 products and 10 are visible at a time and user select 2 products that are visible and then using scroll bar he/she select more 20 products that were not visible then how i can get all the checked check boxes products in this case i have to get 22 products.


Regards,
Altaf
0
Jack
Telerik team
answered on 15 Sep 2009, 08:42 AM
Hi altaf,

The IsSelected property is not related to the checkbox column. As I said in my previous post, it determines whether a cell is selected when you use MultiSelect mode and SelectionMode is set to CellSelect. This is similar to the cell selection in MS Excel.

You should use the Cells collection of GridViewRowInfo to get the cell value. Check the sample below:

List<int> checkedRows = new List<int>(); 
foreach (GridViewDataRowInfo row in this.radGridView1.Rows) 
    if ((bool)row.Cells["Bool"].Value) 
    { 
        checkedRows.Add((int)row.Cells["ID"].Value); 
    } 

I hope this helps. If you need further assistance, please don't hesitate to ask.

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
altaf
Top achievements
Rank 1
Answers by
Jack
Telerik team
altaf
Top achievements
Rank 1
Share this question
or