Dynamically changing DataGridView DataSource in C#
- Using C# and a DataSet/BindingSource set up, I'm trying to dynamically change the DataSource between three views that are part of the DataSet. This code will not work:
this.vwAssignmentsAssignedDataGridView.Enabled = false;
this.vwAssignmentsAssignedDataGridView.DataSource = "vwAssignmentsAssigned";
this.vwAssignmentsAssignedDataGridView.Enabled = true;
Can anybody offer a solution? Thanks.
Answers
- Database source must be a DataSet, DataTable or some kind of Recordset.
If the post is helpful or answers your question, please mark it as such!- Marked As Answer byoldSkule 3 hours 10 minutes ago
- Hi,
The datasource of DataGridViewof any type that implements one of the following interfaces:The IList interface, including one-dimensional arrays.
The IListSource interface, such as the DataTable and DataSet classes.
The IBindingList interface, such as the BindingList<(Of <(T>)>) class.
The IBindingListView interface, such as the BindingSource class.
Could you please be more sepcific about the "views" also what do you mean by the string "vwAssignmentsAssigned";
To change the datasource of datagridview , we can just set the property to different data source.
For more information , please take a look at the documentation:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.datasource.aspx
Harry- Marked As Answer byHarry ZhuMSFT, ModeratorFriday, November 13, 2009 4:30 AM
All Replies
- Database source must be a DataSet, DataTable or some kind of Recordset.
If the post is helpful or answers your question, please mark it as such!- Marked As Answer byoldSkule 3 hours 10 minutes ago
- Hi,
The datasource of DataGridViewof any type that implements one of the following interfaces:The IList interface, including one-dimensional arrays.
The IListSource interface, such as the DataTable and DataSet classes.
The IBindingList interface, such as the BindingList<(Of <(T>)>) class.
The IBindingListView interface, such as the BindingSource class.
Could you please be more sepcific about the "views" also what do you mean by the string "vwAssignmentsAssigned";
To change the datasource of datagridview , we can just set the property to different data source.
For more information , please take a look at the documentation:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.datasource.aspx
Harry- Marked As Answer byHarry ZhuMSFT, ModeratorFriday, November 13, 2009 4:30 AM
- The string bebining w/"vw..." is the name of one of the views I wish to set to display in the datagridview.


