Post subject: Searching a DataGridView for a Value
Editor
Joined: 3/31/2010
Posts: 1466
Location: Not playing Puyo Tetris
I am attempting to search a DataGridView for a value (Str, Dex, Ect.) but I keep getting no results or out of bounds errors. This is the DataGridView I setup and am attempting to searching in.
'Set up Skills chart
        dgvSkills.Columns.Add("col1", "Skill Name")
        dgvSkills.Columns.Add("col2", "Attribute")
        dgvSkills.Columns.Add("col3", "Score")
        dgvSkills.Columns.Add("col4", "Ability Modifier")
        dgvSkills.Columns.Add("col5", "Ranks")
        dgvSkills.Columns.Add("col6", "Misc Modifiers")
        'These are the Untrained ones.  Woo.
        'Skill, Attrib (Title), Skill Total, Ability Mod (Stats), Ranks, Misc (Spells)
        dgvSkills.Rows.Add("Acrobatics", "Dex", "0", "0", "0", "0")
        dgvSkills.Rows.Add("Appraise", "Int", "0", "0", "0", "0")
        dgvSkills.Rows.Add("Bluff", "Cha", "0", "0", "0", "0")
        dgvSkills.Rows.Add("Climb", "Dex", "0", "0", "0", "0")
        dgvSkills.Rows.Add("Craft (Untrained)", "Int", "0", "0", "0", "0")
        dgvSkills.Rows.Add("Diplomacy", "Cha", "0", "0", "0", "0")
        dgvSkills.Rows.Add("Disguise", "Cha", "0", "0", "0", "0")
        dgvSkills.Rows.Add("Escape Artist", "Dex", "0", "0", "0", "0")
        dgvSkills.Rows.Add("Fly", "Dex", "0", "0", "0", "0")
        dgvSkills.Rows.Add("Heal", "Wis", "0", "0", "0", "0")
        dgvSkills.Rows.Add("Intimidate", "Cha", "0", "0", "0", "0")
        dgvSkills.Rows.Add("Perception", "Wis", "0", "0", "0", "0")
        dgvSkills.Rows.Add("Perform (Untrained)", "Cha", "0", "0", "0", "0")
        dgvSkills.Rows.Add("Ride", "Dex", "0", "0", "0", "0")
        dgvSkills.Rows.Add("Sense Motive", "Wis", "0", "0", "0", "0")
        dgvSkills.Rows.Add("Stealth", "Dex", "0", "0", "0", "0")
        dgvSkills.Rows.Add("Survival", "Wis", "0", "0", "0", "0")
        dgvSkills.Rows.Add("Swim", "Str", "0", "0", "0", "0")
My overall objective is to find an ability (Dex) and then change Skill Total and Ability Mod values to reflect the Dex Value. Edit: This appears to work:
        'Lockout Changes
        dgvSkills.AllowUserToAddRows = False
        Dim someText As String = "Dex"
        Dim gridRow As Integer = 0
        Dim gridColumn As Integer = 0
        For Each Row As DataGridViewRow In dgvSkills.Rows
            For Each column As DataGridViewColumn In dgvSkills.Columns
                Dim cell As DataGridViewCell = (dgvSkills.Rows(gridRow).Cells(gridColumn))
                MessageBox.Show(column.ToString & " Cell " & cell.Value.ToString)
                If cell.Value.ToString.ToLower.Contains(someText.ToLower) Then
                    cell.Style.BackColor = Color.Yellow
                    'It's A Dex
                End If
                gridColumn += 1
            Next column
            gridColumn = 0
            gridRow += 1
        Next Row
        'Enable Changes
        dgvSkills.AllowUserToAddRows = True
All I need to do now is edit the Cells and make it work.
When TAS does Quake 1, SDA will declare war. The Prince doth arrive he doth please.