Hello all,
I have this problem with a databound datagrid in a MDI child form. When bounding an empty datatable ( filled by a query which doesn't contain any results) to the datagrid, I actually see 2 rows in the MDI child form. 1 of these rows is an empty row and 1 is a new row. (see code below)
But the datagrid should only display 1 row (the new row), because the datatable doesn't contain any rows (results). Before bounding the datable to the datagrid, it still contains zero rows. while a run-time check (with a button) the datatable contains 1 row.This problem does only occur when the form is functioning as a MDI child form(where the datagrid is located). This problem doesn't occur when I set this form as the start-up form through the project properties.
I hope it clearly describes my problem. Please let me know when it's not clear...
Thanks in advance,
Alwin
'this form is the mdi child form... i used the Northwind database as example database
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Nwind.mdb"
Dim dt As DataTable
dt = New DataTable
Dim myCommand As New OleDbCommand
Dim conn As New OleDbConnection(strConn)
Dim q As String = "SELECT * FROM Products where ProductID = 200"
myCommand.CommandText = q
myCommand.Connection = conn
Dim da As New OleDbDataAdapter
da.SelectCommand = myCommand
da.Fill(dt)
DataGrid1.DataSource = dt
End
Sub