problem formatin row

5 posts, 0 answers
  1. Adiel
    Adiel avatar
    60 posts
    Member since:
    Jun 2012

    Posted 25 Oct 2007 Link to this post

    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 :
    1  void GrvUsers_RowFormatting(object sender, RowFormattingEventArgs e) 
    2        { 
    3                e.RowElement.RowInfo.Cells["Disable"].Value = ((bool)(e.RowElement.RowInfo.DataBoundItem as User).Claims["Disable"]) ? "Disable" : "Enable"
    4                e.RowElement.RowInfo.Cells["Id"].Value = (e.RowElement.RowInfo.DataBoundItem as People).Claims["Id"]; 
    5                e.RowElement.DoubleClick += delegate(object sender1, EventArgs e1) 
    6                { 
    7                    _presenter.EditUserAccunt((e.RowElement.RowInfo.DataBoundItem as User).UserName); 
    8                }; 
    9        } 

    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

  2. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 25 Oct 2007 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Adiel
    Adiel avatar
    60 posts
    Member since:
    Jun 2012

    Posted 28 Oct 2007 Link to this post


    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
  5. Adiel
    Adiel avatar
    60 posts
    Member since:
    Jun 2012

    Posted 28 Oct 2007 Link to this post

    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
  6. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 29 Oct 2007 Link to this post

    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
Back to Top
UI for WinForms is Visual Studio 2017 Ready