Solved

Help with looping through Grid control and check ckeckbox

Posted on 2012-12-25
7
285 Views
Last Modified: 2012-12-25
Hi,

I used the code below with a combobox to check checkboxes depending on utubeItemA (utubeItemA = 0,1,2 would cause checkboxes in first three rows to be checked)

How do I modify the code to do the same with the GridView control? Items is not a property of the GridView control.

  If utubeItemA IsNot Nothing Then
            For i As Integer = 0 To C1ItemA.Items.Count - 1
                If utubeItemA.Split(",").Contains(C1ItemA.Items(i).Text) Then
                    C1ItemA.Items(i).Selected = True
                    Dim CB As CheckBox = C1ItemA.Items(i).FindControl("CheckItemA")
                    CB.Checked = True
                End If
            Next
        End If

Thanks,

Victor
0
Comment
Question by:vcharles
  • 3
  • 2
  • 2
7 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38720084
Use Rows

Grid.Rows(rowindex).Item(columnindex)
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38720105
do something like:

 For i As Integer = 0 To gridView.Rows.Count - 1
            Dim cb As CheckBox = CType(gridView.Rows(i).FindControl("YourCheckBox"), CheckBox)
If utubeItemA.Split(",").Contains(gridView.Rows(i).Text) Then
            cb.Checked = True
  End If
        Next

Open in new window

0
 

Author Comment

by:vcharles
ID: 38720125
Thanks, If I am not using the checkbox, How do I just highlight the row?
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 38720130
Dim tokens As String() = utubeItemA.Split(",")

For Each row As DataGridViewRow In gridView.Rows
           If tokens.Contains(row.Text) Then
row.DefaultCellStyle.BackColor = Color.Red
  End If
Next

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38720156
You can also set the row to Selected
0
 

Author Comment

by:vcharles
ID: 38720159
Thanks I will try them and get back to you.
0
 

Author Closing Comment

by:vcharles
ID: 38720211
Thank You!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

19 Experts available now in Live!

Get 1:1 Help Now