Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help with selecting rows in Grid based on string value

Posted on 2013-01-03
8
Medium Priority
?
353 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
PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

 

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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

721 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