Link to home
Start Free TrialLog in
Avatar of Victor  Charles
Victor CharlesFlag for United States of America

asked on

Help with selecting rows in Grid based on string value

Hi,
 I tried the code below to select rows 2 and 3 (utubeC = "1,2") but getting error message: Not supported when the Grid is bound
on line:
If utubeC.Split(",").Contains(C1SDeactivation.Rows(i).ToString) Then
 
utubeC = "1,2"
C1SDeactivation.ClearFields()
For i As Integer = 0 To C1SDeactivation.RowCount - 1
If utubeC.Split(",").Contains(C1SDeactivation.Rows(i).ToString) Then
C1SDeactivation.SelectedRows.Add(i)
End If
Next
 
How do I fix this error?
 
I am using a TrueDBGrid from componentOne, but hoping solution for GridView will also solve this issue.

Victor
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

>If utubeC.Split(",").Contains(C1SDeactivation.Rows(i).ToString) Then

Should that not be

If utubeC.Split(",").Contains(C1SDeactivation.Rows(i).Cells(CellIndex).Value.ToString) Then
Avatar of Victor  Charles

ASKER

Hi,

Thanks for the code, when I tried it, I received error messsage: "CellIndex is not declared it may be inaccessible due toi its protection level.
When I use undeclared variables in my code examples, I expect you to replace those appropriately. What CellIndex meant is... index of the column that you are trying to check (such as ID) just like you are using i as rowindex.
I am checking the string variable against the first column in the Grid.

 SDeactivation_ID  SDeactivation
0                             ItemA
1                             ItemB
2                             ItemC
3                             ItemD

Tried the following code:

 If utubeC.Split(",").Contains(C1SDeactivation.Rows(i).Cells(SDeactivation_ID).Value.ToString) Then

But it still does not work. Error SDeactivation is not declared,it may be inaceesible to to its protection level.

Also tried:

 If utubeC.Split(",").Contains(C1SDeactivation.Rows(i).Cells("SDeactivation_ID").Value.ToString) Then
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That also did not work, waiting to hear back from componentOne.

Thanks,

Victor
I'm not getting an error with code below but i  is stuck in 0, any ideas why?
I tried i = i + 1 within the loop but msgbox value only shows 0, which i assume is the value for the first row.

 For i As Integer = 0 To C1SDeactivation.RowCount - 1
            MsgBox(C1SDeactivation.Columns(0).Value.ToString)
                    If utubeC.Split(",").Contains(C1SDeactivation.Columns(0).Value.ToString)
Then
 C1SDeactivation.SelectedRows.Add(i)
            End If
        Next
You are only using .Columns collection without any reference to a row hence same value all the time.