Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > I had to implement additional data sources for DataGridView
 

I had to implement additional data sources for DataGridView

Once data is bound to the DataGridView control, the behavior of the control becomes very hard to influence and I saw only one way out, and that is to implement data binding by overriding the control's DataSource property and simply not bind data to the base control itself.

I ran into problems when I wanted to use the following code in unbound mode:

private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
{
DataGridViewRow row = dataGridView1.Rows[e.RowIndex];

MyItem item1 = row.DataBoundItem as MyItem;

//trying to do something with item1 but item1 is null at this point
}

Could you tell me how can I assign DataGridViewRow.DataBoundItem property for newly create rows if I create rows using code like this? :

internal class MyRow : DataGridViewRow
{
...
}

MyRow row_temp = new MyRow();

row_temp.CreateCells(dataGridView1, "val1", "val2");

Dmitriano  Friday, September 01, 2006 8:42 AM
This is off topic for the Visual C# General forum, moving to the Windows Forms Data Controls and Databinding forum.
Peter Ritchie  Saturday, September 02, 2006 3:33 PM

You can use google to search for other answers

Custom Search

More Threads

• Filter DataGridView by Parent/Child Relationships
• Row Selection in Datagrid
• How to assign Data table object to BindingSource
• DataGridViewTextBoxColumn cell padding problem
• Update Expression Column in DataGrid
• receive of class udpclient in vs 2003...
• Bug in DataGridView or example by Mark Rideout
• Bindable User Control always causes HasChanges
• Set Default value on new record in BindingSource / BindingNavigator scenario
• is it Concurrency violation a bug?