Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Problem with Databound DataGrid on a MDI Child form
 

Problem with Databound DataGrid on a MDI Child form

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


 

Alwin  Monday, July 04, 2005 7:28 AM
Hi,


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
Paul Domag  Monday, July 04, 2005 9:09 AM
Hi,


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
Paul Domag  Monday, July 04, 2005 8:07 AM
I already did a check to display the number of rows after filling the datatable, and also a check before and after bounding the datatable to the datagrid... it displays 0 rows.

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
Alwin  Monday, July 04, 2005 8:38 AM
Hi,


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
Paul Domag  Monday, July 04, 2005 9:09 AM

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...

Alwin  Monday, July 04, 2005 9:55 AM
Hi,


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
Paul Domag  Monday, July 04, 2005 3:47 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGridView, DataGridViewComboBoxColumn
• how to Prevent duplicate INSERTs
• Reading datareader using a for loop.
• How to read xml into a listbox
• load data only if needed...
• Datagrid column heading
• Unretrivable data from single selected checkboxes in datagridview
• Copying 1 APP to Another
• Hiding public properties when binding to a datagrid
• How to show wait cursor (hourglass) in DataGridView