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

Re: Question about DataTable and DataGrid by Dmitriy

Dmitriy
Mon Feb 09 07:05:34 CST 2004

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" <anonymous@discussions.microsoft.com> wrote in message
news:5540BB6F-1A10-469D-9166-973FC1CB2BC4@microsoft.com...
> 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
>