We help IT Professionals succeed at work.

Set a value in a DataGrid cell

redundguy asked
Medium Priority
Last Modified: 2012-06-21
I work in VB6 with a DataGrid control. I try to validate data in a BeforeColUpdate event of DataGrid. When the value is wrong I want to correct the value. I use the folowing statement, like in VB Help documentation:
but this statement doesn't work - it does nothing, the old value remains.
How can I set a value in a DataGrid column ?

Watch Question

Head of Software Services
redundguy, as you are using the beforecolupdate event, I doubt whether the grid is seeing this change in value. If you are updating the value in the BeforeColUpdate event, set Cancel = True before your DataGrid1.Columns(ColIndex).Value=correct_value statement in the event procedure. This will prevent the entered value being accepted and will use your validated new value instead.


Thank you.
I have found a second way to change the data in a DataGrid cell: I make the change in the AfterColUpdate event.
TimCotteeHead of Software Services

That works too!


I have been developing a VB6 database application (Fixed Assets Management) using Object Oriented Design and Three Tiers Architecture. I have managed to design the Input-Data section of the application using only some form controls like ListView, TextBox, ComboBox, CommandButtons, RadioButtons, and the data input process run very well (I have master-detail structure, foreign keys and all the things of a real application).
Now I have a new VB6 application and I try to use other controls, like DataGrid or HierarchicalFlexGrid, in order to improve the designing and programming process. But I have a lot of troubles with these controls. For example after I add a record in a DataGrid I cannot immediately delete it. And I think that the operate with this control is not very clear for a user. Also it is difficult to use an updateable DataGrid when I have foreign keys on the underlying table.
I think that is better to use simpler controls : maybe I have to write more code, but I think the program will become more robust.
What do you think?

Explore More ContentExplore courses, solutions, and other research materials related to this topic.