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

problem formatin row

4 Answers 158 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Adiel
Top achievements
Rank 2
Adiel asked on 25 Oct 2007, 12:07 PM
Hi
I have strange problem.
I put a radGridView and bind it to collection.
2 added Columns need to format so I handle "RowFormating" and format them there.
another thing is that i want to do some actions when a row Double clicked so i add a delegate there.
here is some code :
  void GrvUsers_RowFormatting(object sender, RowFormattingEventArgs e) 
        { 
                e.RowElement.RowInfo.Cells["Disable"].Value = ((bool)(e.RowElement.RowInfo.DataBoundItem as User).Claims["Disable"]) ? "Disable" : "Enable"
                e.RowElement.RowInfo.Cells["Id"].Value = (e.RowElement.RowInfo.DataBoundItem as People).Claims["Id"]; 
                e.RowElement.DoubleClick += delegate(object sender1, EventArgs e1) 
                { 
                    _presenter.EditUserAccunt((e.RowElement.RowInfo.DataBoundItem as User).UserName); 
                }; 
        } 

this code work correctly but I deed some cosmetic changes and now it throw that exception:"Collection was modified; enumeration operation may not execute."

if I keep going it's render the grid very tight to left, if I change the general size of the window it's automatically render correct...

any ideas
thanks.
Adiel

4 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 25 Oct 2007, 02:28 PM
Hi Adiel,

Thank you for this question.

Actually, it is not quite correct to attach to events inside the RowFormatting event. The RowFormatting event fires every time a row needs to update its visual state. This will cause your code (inside the DoubleClick event) to be executed many times for the same row element. We suggest you use the CellDoubleClick and the CellFormatting events instead. Refer to the code sample below:

this.radGridView1.CellFormatting += new CellFormattingEventHandler(radGridView1_CellFormatting); 
this.radGridView1.CellDoubleClick += new GridViewCellEventHandler(radGridView1_CellDoubleClick); 
 
void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) 
    GridViewDataColumn column = e.CellElement.ColumnInfo as GridViewDataColumn; 
    if (column != null
    { 
        if (column.DataField == "Disable"
        { 
            e.CellElement.Value = ((bool)(e.CellElement.RowInfo.DataBoundItem as User).Claims["Disable"]) ? "Disable" : "Enable"
        } 
        if (column.DataField == "Id"
        { 
            e.CellElement.Value = ((bool)(e.CellElement.RowInfo.DataBoundItem as People).Claims["Id"];  
        } 
    } 
 
void radGridView1_CellDoubleClick(object sender, GridViewCellEventArgs e) 
    _presenter.EditUserAccunt((e.RowElement.RowInfo.DataBoundItem as User).UserName);  
 

If this does not help you address the issue, please send us your application and we will investigate further.
If you have any additional questions, please do not hesitate to contact us.

Regards,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Adiel
Top achievements
Rank 2
answered on 28 Oct 2007, 09:42 AM

Hi
thanks for reply.
but...  
1. e.CellElement.Value  - is readonly... (I use SetValue...)
2.  I  comment  all  that  code and  it's steel  happen.  so  it's not  because of that grid rows.

I steel get that "Collection was modified; enumeration operation may not execute."

thanks
Adiel
0
Adiel
Top achievements
Rank 2
answered on 28 Oct 2007, 10:02 AM
Catch it !!!!
if I change autoScroll property to false it work fine....
if it true and i havn't enough space to the control the problem occur.
Thanks anyway.
Adiel
0
Jack
Telerik team
answered on 29 Oct 2007, 12:08 PM
Hi Adiel,

We are glad to hear that your issue is solved.

Indeed, you are correct - the GridCellElement.Value property is read only. This was my mistake. You should use the GridCellElement.SetCellValue method instead.

Contact us again, if you have any additional questions. We will be happy to help.

Greetings,
Jack
the Telerik team

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