Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGridView Question...

Status
Not open for further replies.

sqlsamurai

Programmer
May 11, 2005
120
US
I have validation code in my cellvalidating event. The only problem is that when i move to a new row in my datagrid the validating event fires. Why is this? Obviously I dont want the validating event to fire unless I've tried to enter something in the particular cell. I'm using a DataGridView control in Visual Studio 2005.

Thanks
 
Samurai, I've had similar problems with my datagrid.

I can tell you what worked for me.

On your form load event, create a pointer to each column, add a handler to each of them, and then create the method you want to fire when the event happens.

Code:
Friend WithEvents txtSomeFld As DataGridTextBox

Private sub Form1_Load(byval sender as Object, ByVal e As System.EventArgs) Handles MyBase.Load


  txtSomefld = Me.SomeFld.TextBox

   AddHandler txtSomefld.TextChanged, AddressOf 
  txtSomeFld_changed

End sub

'''''''Other Code ''''

Private sub txtSomeFld_Changed(byval Sender as object, byval e as system.eventargs) 

''' do something'''


end sub

Make sure Me.SomeFld is the actual name of the column in the grid.

You can find this by looking at the Windows Form Desinger generated code. Actually, you should know what it is if you designed the grid, right?

Anyway, hope this helps.

- mongril
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top