Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataTable like binding
 

DataTable like binding

Hi,

I have a class that represents a row of data and a class that represents a column definition and value. If my row contains a collection of columns with their values how hard is it to get the DataGridView to bind to the row (or a collection of rows) and for it to use my column collection to obtains both the column names for the grid and the cell values?

I have tried doing this with the DataTable and it just works, now I want to do it with my own classes.

Any help would be great!

Regards

Graham

LordTitan  Wednesday, August 13, 2008 9:19 AM

Hi LordTitan,

As Ken said, if the row contained property for each column, it will be easy for you to bind DataGridview to the row. You can try to use BindingSource component. For details, please refer to How to: Bind Objects to Windows Forms DataGridView Controls.

As for the second question, it is because DataTable implements IListSource interface and DataGridView class support the standard Windows Forms data-binding model.

If you have further problems, please don’t hesitate to let me know.

Best Regards,

Bruce Zhou

Windows Forms General FAQs
Windows Forms Data Controls and Databinding FAQs

Bruce.Zhou  Monday, August 18, 2008 3:30 AM
If your row contained a property for each column this would be very easy. Since your row contains a collection it would very hard.

Ken Tucker  Wednesday, August 13, 2008 10:52 AM

Thanks for the quick reply.

Does you know how a DataTable managed to do it?

LordTitan  Wednesday, August 13, 2008 11:44 AM

Hi LordTitan,

As Ken said, if the row contained property for each column, it will be easy for you to bind DataGridview to the row. You can try to use BindingSource component. For details, please refer to How to: Bind Objects to Windows Forms DataGridView Controls.

As for the second question, it is because DataTable implements IListSource interface and DataGridView class support the standard Windows Forms data-binding model.

If you have further problems, please don’t hesitate to let me know.

Best Regards,

Bruce Zhou

Windows Forms General FAQs
Windows Forms Data Controls and Databinding FAQs

Bruce.Zhou  Monday, August 18, 2008 3:30 AM

You can use google to search for other answers

Custom Search

More Threads

• Help: Datagridview is not show all data!!!
• DataGridView Column Header
• Find Values in a DataTable
• programatically add new row to datagrid
• Listbox and datasource
• DataGridView -Question
• date field may be null how can i do this in Access
• listview dataview
• RadioButtonColumn in DataGridView
• Accessing null value from datatable