Solved

Help with selecting rows in Grid based on string value

Posted on 2013-01-03
8
352 Views
Last Modified: 2013-01-04
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
0
Comment
Question by:vcharles
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38742085
>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
0
 

Author Comment

by:vcharles
ID: 38742175
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.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38742234
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.
0
Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

 

Author Comment

by:vcharles
ID: 38742274
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
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 38742349
Also try

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

Note that .Cells is a GridView way of doing this. Your control may have some other name to correspond to this or may not have this at all.
0
 

Author Comment

by:vcharles
ID: 38742502
That also did not work, waiting to hear back from componentOne.

Thanks,

Victor
0
 

Author Comment

by:vcharles
ID: 38742561
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
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38743320
You are only using .Columns collection without any reference to a row hence same value all the time.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question