Solved

Help with selecting rows in Grid based on string value

Posted on 2013-01-03
8
346 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
  • 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
 

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now