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

Mixed bound and unbound columns

6 Answers 366 Views
GridView
This is a migrated thread and some comments may be shown as answers.
superold
Top achievements
Rank 1
superold asked on 20 Aug 2010, 05:16 PM
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

6 Answers, 1 is accepted

Sort by
0
Accepted
Julian Benkov
Telerik team
answered on 25 Aug 2010, 04:49 PM
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
0
superold
Top achievements
Rank 1
answered on 30 Aug 2010, 01:34 PM
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
0
Julian Benkov
Telerik team
answered on 02 Sep 2010, 04:28 PM
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
0
superold
Top achievements
Rank 1
answered on 08 Sep 2010, 01:01 PM
thank you. i noticed that setting the datasource populates the grid. 
0
David A.
Top achievements
Rank 1
answered on 09 Jan 2012, 10:44 AM
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.

0
Julian Benkov
Telerik team
answered on 12 Jan 2012, 09:57 AM
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).

Tags
GridView
Asked by
superold
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
superold
Top achievements
Rank 1
David A.
Top achievements
Rank 1
Share this question
or