Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #13536 |

    I am trying to change the row color upon double click. Grid will be populated upon selected in the combo box. Nothing happends when I doulecllick on the the grid unless i select the combo twice (populating the grid twice). Seems to be the focus going somewhere out of the grid. Anyone here to help me?

    Here’s the code:

    private sub fillGrid
    …………………
    ………………….
    grdMenus.DataSource = menusDS.Tables(“menus”)
    Dim cell As DataCell
    For Each cell In grdMenus.DataRowTemplate.Cells
    AddHandler cell.DoubleClick, AddressOf selectMenus
    Next
    end sub

    Private Sub selectMenus(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Try
    Dim row As CellRow = grdMenus.CurrentRow
    If row.ForeColor= Color.Red Then
    row.ResetForeColor()
    Else
    row.ForeColor = Color.Red
    End If
    Catch ex As Exception
    Exit Sub
    End Try
    End Sub

    Imported from legacy forums. Posted by PETE (had 868 views)

    User (Old forums)
    Member
    Post count: 23064

    Whenever ‘double click’ event occured, selectMenus sub being accessed more than 10 times. where am i doing the mistake?

    Imported from legacy forums. Posted by PETE (had 274 views)

    User (Old forums)
    Member
    Post count: 23064

    I see you use a Try…Catch-block, and just ignore the exception. Maybe you should put a breakpoint in the Catch-block, and see if an exception occurs.

    I also see you use grdMenus.CurrentRow to find out what row was double-clicked. This might not always be accurate. I think it’s better to cast the sender-argument to Cell, and get the ParentRow of that cell, like this:<code>Dim cell As Cell = sender
    Dim row As CellRow = cell.ParentRow</code>

    PS: You should only add the double-click event once, not each time you populate the grid.

    Imported from legacy forums. Posted by Tommy (had 245 views)

    User (Old forums)
    Member
    Post count: 23064

    Thank you Tommy. You are always there for this forum.

    As you answered, I did two things to make it work.

    1. instead of grid.currentRow, I used cell as the sender argument
    2. I put the double-click event at form_load

    Thank You.

    Imported from legacy forums. Posted by PETE (had 3789 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.