Question about DataTable and DataGrid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

- I have created a table that has 4 columns (type System.String) - called myDataTable. The table is created during the Form_Load function.

- I have created a DataGrid, called dataGrid1.

Now, to my problem:
Each time my user clicks on the "search" button, a search is performed, the table is cleared with myDataTable.clear() and filled with the new data. Then I want to bind the DataGrid to the table, using dataGrid1.DataSource = myDataTable -- which contains the new results each time. But - I am getting an exception. Since I have tried to debug this, I am almost positive that the problem is related to the binding. Can someone offer help? or shed some light on how to bind the Grid to a table?

Actually I would love to know if there is a way to fill the DataGrid control without messing around with tables or datasets...
BTW - I am using C#

Thanks
 
Hi,

Try the SetDataBinding method instead of assigning the DataSource property
directly.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Pry said:
Hi,

- I have created a table that has 4 columns (type System.String) - called
myDataTable. The table is created during the Form_Load function.
- I have created a DataGrid, called dataGrid1.

Now, to my problem:
Each time my user clicks on the "search" button, a search is performed,
the table is cleared with myDataTable.clear() and filled with the new data.
Then I want to bind the DataGrid to the table, using dataGrid1.DataSource =
myDataTable -- which contains the new results each time. But - I am getting
an exception. Since I have tried to debug this, I am almost positive that
the problem is related to the binding. Can someone offer help? or shed some
light on how to bind the Grid to a table?
Actually I would love to know if there is a way to fill the DataGrid
control without messing around with tables or datasets...
 
Back
Top