Mixed bound and unbound columns

7 posts, 1 answers
  1. Jorge Delgado-Lopez
    Jorge Delgado-Lopez avatar
    82 posts
    Member since:
    Aug 2007

    Posted 20 Aug 2010 Link to this post

    Hi.

    I have defined a set of columns that are bound to my BindingList<RowEntry> collection. This works like it should. I am now in the process of adding some extra columns dynamically. How do I populate these? is there a "DidNotFoundPropertyManuallySetCellData" event? :-)

    /jorge
  2. Answer
    Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 25 Aug 2010 Link to this post

    Hi Jorge Delgado-Lopez,

    When you add a column without setting its FieldName, the column is set in unbound mode and you can directly get/set its cell values:

    GridViewTextBoxColumn unboundColumn = new GridViewTextBoxColumn();
    unboundColumn.Name = "Unbound";
    radGridView1.Columns.Add(unboundColumn);
     
    radGridView1.Rows[0].Cells["Unbound"].Value = "MyValue";

    Greetings,
    Julian Benkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Jorge Delgado-Lopez
    Jorge Delgado-Lopez avatar
    82 posts
    Member since:
    Aug 2007

    Posted 30 Aug 2010 Link to this post

    Thanks for the answer. The next question would be where do I populate these columns?

    Bind first and loop through rows after? Or should I use some grid event since the columns are not shown by default (IsVisible = false) it would be great if I can populate them when needed. 

    Thanks
    - jorge
  4. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 02 Sep 2010 Link to this post

    Hello Jorge Delgado-Lopez,

    To populate a row in inbound mode you can loop through the rows collection:

    foreach (GridViewDataRowInfo row in radGridView1.Rows)
    {
        row.Cells["MyColumn1"].Value = "Value1";
        row.Cells["MyColumn2"].Value = "Value2";
        //...
    }

    Sincerely yours,
    Julian Benkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Jorge Delgado-Lopez
    Jorge Delgado-Lopez avatar
    82 posts
    Member since:
    Aug 2007

    Posted 08 Sep 2010 Link to this post

    thank you. i noticed that setting the datasource populates the grid. 
  6. David A.
    David A. avatar
    126 posts
    Member since:
    Aug 2008

    Posted 09 Jan 2012 Link to this post

    I have the same scenario with bound and unbound columns but the grid datasource shares a binding context with a popup form that edits the grid data.  When I make a change to an unbound column, is there an event with the GridView that will fire to refresh the row in the Grid?  I tried the CellFormatting event but I found that this event if not very efficient to populate cells with. I also tried the CellValueNeeded but it did not fire (Virtual Mode only?)

    I would like to know 2 things:
    1. In what grid event should unbound data be populated?
    2. Is there an event that is raised when a row's DataBoundItem has changed?

    Thank you.

  7. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 12 Jan 2012 Link to this post

    Hello David,

    To populate a row in inbound mode you can loop through the rows collection:

    foreach (GridViewDataRowInfo row in radGridView1.Rows)
    {
        row.Cells["MyColumn1"].Value = "Value1";
        row.Cells["MyColumn2"].Value = "Value2";
        //...
    }

    This will automatically refresh the current view of RadGridView control. The updated logic can be processed after you change some part of your data objects or after the end-user interacts with other UI elements in your application. If you want to update the information using RadGridView editing and then sync this unbound values from RadGridView control to an external data object you can use CellValueChanged or RowsChanged events. In bound mode when a DataBoundItem is changed, RadGridView will automatically refresh, if the DataSource object implement IBindingList interface. More information about binding notifications you can find in this article.

    I hope this information is useful. Let me know if you need further assistance.

    Greetings,
    Julian Benkov
    the Telerik team

    SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

Back to Top