Wednesday, August 13, 2014

Datagrid object bug in Visual Basic 6.0 (SP6)

Noticed strange bug or some undesirable feature while developing application in Visual Basic 6.0 IDE.  I have static Data objects drag & dropped on Form. Objects are of type Adodc and Datagrid. Adodc properties (ConnectionString and RecordSource) are empty. I fill them during run time and then refresh in my code. Then comes this bug. Datagrid which is connected to adodc object already at design time, tries to delete leftmost upper data grid cell content. And if database field allows empty value, then this deletion really happens. And it all goes on even data grid properties are set not to allow updates, additions and deletions. DataGrid control and ADO Data Control both are updated to Service Pack 6. I tried several things and finally found a workaround.
You must also clear data grid property 'DataSource' and set the value during run-time. Below is example code. 


Adodc1.ConnectionString="Provider='Microsoft.Jet.OLEDB.4.0';Data Source='database.mdb';Persist Security Info='False'"
Adodc1.RecordSource="SELECT * FROM Firms"
Adodc1.Refresh
 
Set DataGrid1.DataSource=Adodc1
DataGrid1.Refresh

Using this code data in first cell is not being deleted anymore. You can try yourself if you have similar problem.

No comments:

Post a Comment