Jump to content


Photo

Prevent new entry until both columns filled


  • Please log in to reply
1 reply to this topic

#1 timdav83

timdav83

    Young Padawan

  • Members
  • Pip
  • 17 posts

Posted 07 April 2010 - 02:27 AM

I'm still rather new to vb.net. I have a datagridview (default name) with 2 columns. Both use the default name (Column1, Column2). One column has a combo box with pre-entered text, the second column is a text box. I would like to prevent the new row from appearing if both columns are not filled out completely. So when Column 1 is in edit mode, column 2 is checked for data input as well...

After some searching through google, I came across a similar code to the following which checks if a cell is in edit mode, I made a small modification to validate a row, but am not sure how to do the above.

Public Class Form1

	Private Sub DataGridView1_CellValidating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles DataGridView1.CellValidating
		Dim cell As DataGridViewCell = DataGridView1.Item(e.ColumnIndex, e.RowIndex)


		If cell.IsInEditMode Then

			Dim c As Control = DataGridView1.EditingControl

			Select Case DataGridView1.Columns(e.RowIndex).Name
				Case "Column1"
					MsgBox(c.Text)
				Case "Column2"
					MsgBox(c.Text)
			End Select
		End If
	End Sub
End Class

The odd thing about rowindex is the fact that it also freezes the program when more then 2 entries have been made...

Edited by timdav83, 07 April 2010 - 02:01 PM.


#2 timdav83

timdav83

    Young Padawan

  • Members
  • Pip
  • 17 posts

Posted 07 April 2010 - 02:21 PM

I found this which cancels the edditing process:
http://msdn.microsof...y/ykdxa0bc.aspx

However, it does not help with checking both column 1 and column 2 at the same time.

Perhaps results on google exist, but I'm not sure of the search query.

Edited by timdav83, 07 April 2010 - 03:50 PM.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users