How Do I set defaults for a cell in a datagridview in VB.net 2.0 winforms?
Posted on 2006-03-23
I have some examples from a book (VB2005 DB Programming - wrox press) I'm trying to follow.
I have a Datagridview on a form.
on the top of the form is the standard first, prev, counter, next, last navigation buttons
next to them are buttons to add and delete a record (and of course the save button)
I need to default one field in the table when a new record is added.
I added the following procedures: (per page 150-151)
Private Sub UsersDataGridView_DefaultValuesNeeded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles UsersDataGridView.DefaultValuesNeeded
Private Sub setdefaults(ByVal rowadded As DataGridViewRow)
rowadded.Cells("DataGridViewTextBoxColumn8").Value = "EGL"
The above code works great if I click anywhere in the row indicated by the >* symbol on the left - both msgboxes display and my value is added.
However it doesn't fire if I click the yellow + Icon on the navigation toolstrip.
I tried this but it didn't work:
Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorAddNewItem.Click
Dim x As System.Windows.Forms.DataGridViewRowEventArgs
x = CType(e, System.Windows.Forms.DataGridViewRowEventArgs)
Thanks in advance for your help on this!