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

Problem with Databound DataGrid on a MDI Child form
WileyWes
and since this is the only code i have in my project (the mdi parent form only calls the child form), nothing adds rows to my table...
Can you please give me a hint where to search in the MDI area, because i have no clue.
thanks,
Alwin
zproxy
That would be a very good idea...
Just mail it to me so i can tinker with it...
pauldomag@gmail.com
cheers,
Paul June A. Domag
mike11d11
Try displaying the number of rows after you fill the DataTable to check if the result set is really empty. Also, don't forget to open your connection when you execute the Fill method. There might be some codes in your project that adds these rows into your table. Try investigating in the MDI area, coz its the first logic to be executed...
cheers,
Paul June A. Domag
Eric from Plainwrap
Hi Paul,
Thanks for trying it out... I'm using VS.Net 2003.
I tried other tables and tried to recreate it again.. .actually, the code which i gave in the first place is already a recreation (a test project)! AND, it happened again! weird huh But that's why i post it here...
If you want I can send the test project...
MsMe
I just tried it using VS2005 B2. It works just fine. Have you tried using other tables Or you could try recreating it again. And see if it still happens.
Please post step by step instructions on how to reproduce your problem...
cheers,
Paul June A. Domag