|
-
Oct 27th, 2002, 06:37 PM
#1
Thread Starter
Registered User
Validating Data Entry with a datagrid
I have loaded data into the grid and the next thing that I want to be able to do is:
1. Validate user entry that is make sure they haven't placed alphas where I only wanted numbers. Anyone got any suggestions?
2. Limit the number of characters users can put in the grid. Again suggestions appreciated.
-
Oct 27th, 2002, 06:38 PM
#2
PowerPoster
Hmm...I haven't used the data grid extensively, but does it expose properties on a per column basis? I've used alot of grids that allow this, but as I stated, I really havent used the data grid.
-
Oct 27th, 2002, 06:45 PM
#3
Thread Starter
Registered User
found out how to do 2, you can play with this sorta stuff with
DataGridTextBoxColumns
eg
txtCol.TextBox.MaxLength= x
but still need to work out how to validate user entry?
-
Oct 27th, 2002, 06:51 PM
#4
Thread Starter
Registered User
Originally posted by Lethal
Hmm...I haven't used the data grid extensively, but does it expose properties on a per column basis? I've used alot of grids that allow this, but as I stated, I really havent used the data grid.
Yeah the new datagrid is pretty cool in that it allows you to directly bind multiple tables to a datagrid at once and the user can just select which table they want to see. The only problem that I am finding is that as soon as you want to start mucking around with the defaults, you gotta learn the object model beneath the control and in this case there are a couple such as DataGridTableStyle and GridColumnStyles that you have to get comfy with. So I am flying in the dark a little here, but I guess it is kinda fun, like having your girlfriend think it's funny to wax your leg, "no sweetie my leg is killing, don't go any higher and do my arms"
-
Oct 27th, 2002, 06:56 PM
#5
PowerPoster
How bout something like this?
Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim iDigit = System.Convert.ToInt32(e.KeyChar)
Dim bSpace = (iDigit = 32)
Dim bBackSpace = (iDigit = 8)
If Not System.Char.IsDigit(e.KeyChar) Then
If (Not bSpace And Not bBackSpace) Then
e.Handled = True
End If
End If
End Sub
Last edited by Lethal; Oct 27th, 2002 at 07:14 PM.
-
Oct 27th, 2002, 07:53 PM
#6
Thread Starter
Registered User
Tried this but nothing was printed in the debug window 
Code:
Private Sub DataGrid1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DataGrid1.KeyPress
Debug.WriteLine(Me.DataGrid1.CurrentCell.RowNumber)
Debug.WriteLine(e.KeyChar)
' check for your active column to restrict input
'If Not System.Char.IsDigit(e.KeyChar) Then
' If Not System.Char.IsControl(e.KeyChar) And Not e.KeyChar = CType(e.KeyChar, Char) Then
' e.Handled = True
' End If
'End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|