G
Guest
The procedure below checks if a character entered into a cell of a
datagridview is contained in a string array of valid characters for this
particular cell. It seems kludgy. I am asking what the best practice would
be. I was thinking I could use an arrayList which has the "contains"
property and do this:
If not arr.Contains(s1) then --- don't continue
but my list of codes might be about 50 char combinations. So I was thinking
a string array. But with the string array I can only think of checking the
value using loops in the following kludge procedure
Dim s1 As String, b1 As Boolean
s1 = StrConv(dgrv1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString,
VbStrConv.Uppercase)
b1 = False
If s1 <> "" Then
Dim arr() As String = New String() {"C", "D", "F", "I", "N", "P", "R", "U"}
For Each str1 As String In arr
If s1.Equals(str1) Then
b1 = True
Exit For
End If
Next
If b1.Equals(False) Then
Beep()
MessageBox.Show("Invalid code for this cell")
dgrModSubDetail.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = ""
End If
End If
At least with this kludge I don't have 50 lines of code to load the
arraylist. What is the best practice to perform this procedure? Is there
any method like
If s1 Not In {"C", "D", "F", ...}
Thanks,
Rich
datagridview is contained in a string array of valid characters for this
particular cell. It seems kludgy. I am asking what the best practice would
be. I was thinking I could use an arrayList which has the "contains"
property and do this:
If not arr.Contains(s1) then --- don't continue
but my list of codes might be about 50 char combinations. So I was thinking
a string array. But with the string array I can only think of checking the
value using loops in the following kludge procedure
Dim s1 As String, b1 As Boolean
s1 = StrConv(dgrv1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString,
VbStrConv.Uppercase)
b1 = False
If s1 <> "" Then
Dim arr() As String = New String() {"C", "D", "F", "I", "N", "P", "R", "U"}
For Each str1 As String In arr
If s1.Equals(str1) Then
b1 = True
Exit For
End If
Next
If b1.Equals(False) Then
Beep()
MessageBox.Show("Invalid code for this cell")
dgrModSubDetail.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = ""
End If
End If
At least with this kludge I don't have 50 lines of code to load the
arraylist. What is the best practice to perform this procedure? Is there
any method like
If s1 Not In {"C", "D", "F", ...}
Thanks,
Rich