I am using the code below to select rows in a Grid where values of SDeactivation is found agains SDéactivation_ID which is in Coumn(2). SDeactivation_ID contains single values.
When SDeactivation is a single value all is working of but when SDeactivation includes multiple values (i.e. 1,2,3) it does not work. How do i modify the code to select rows when using multiple values for SDeactivation?
MsgBox("keySDeactivation)" & keySDeactivation)
' keySDeactivation = "1,2" does not works
' keySDeactivation = "1" works
If keySDeactivation <> "" Then
Dim _tableA As DataView = dtMasterA.DefaultView
C1SDeactivation.DataSource = _tableA
For i As Integer = 0 To C1SDeactivation.RowCount - 1
If C1SDeactivation.Columns(2).CellValue(i).ToString().Contains(keySDeactivation) = True Then
C1SDeactivation.SelectedRows.Add(i)
End If
Next
End If
Thanks,
Victor
Microsoft Access.NET ProgrammingVisual Basic.NETSQL
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
To make sure that 1 does not match with 11 using Contains function, I would add commas at start and end of the keySDeactivation and do following comparison
Thank You for all the comments. This thread was the solution.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Nasir Razzaq
You are sure you wont have numbers greater than 9 in there?
vcharles
ASKER
Yes, that is ok, those are just values of the ID fields I will use to select the rows.
Thanks.
Victor
Nasir Razzaq
And you will never have an ID greater than 9(such as 10, 11 etc). The reason I ask is that using the contains method as you are, 1 will match if there is 11 but no 1. So if you are trying to select just 11, both 1 and 11 will get selected.
Outside loop:
keySDeactivation = "," & keySDeactivation & ","
Inside Loop:
If keySDeactivation.Contains(