XtraGrid: Get RespositoryItemButtonEdit row index

2019-08-10 18:09发布

问题:

How to get ButtonEdit at specific row index?

This is how I am creating RepositoryItemButtonEdit column.

Private Sub PopulateDataGrid()

    GrdCntrlMain.DataSource = CreateDataSet().Tables(TABLE_WORKERS)

    Dim lObj_GrdClmn As GridColumn = GrdView.Columns.AddField("Select") ' This is my RepositoryItemButtonEdit column
    With lObj_GrdClmn
        .VisibleIndex = GrdView.Columns.Count
        .OptionsColumn.AllowEdit = True
    End With

    GrdView.OptionsView.RowAutoHeight = False

    AddHandler GrdView.MouseMove, AddressOf GrdView_MouseMove

    Dim lObj_RepItm_BtnEdt As New RepositoryItemButtonEdit
    lObj_RepItm_BtnEdt.TextEditStyle = TextEditStyles.HideTextEditor

    AddHandler lObj_RepItm_BtnEdt.ButtonPressed, AddressOf lObj_EdtrBtn_Click

    Dim lObj_EdtrBtn As EditorButton = New EditorButton()
    lObj_EdtrBtn.Kind = ButtonPredefines.Glyph
    lObj_EdtrBtn.Appearance.BackColor = Color.Azure
    lObj_EdtrBtn.Caption = "Remove"
    lObj_EdtrBtn.Appearance.Options.UseTextOptions = True

    lObj_RepItm_BtnEdt.Buttons.Clear()

    lObj_RepItm_BtnEdt.Buttons.Add(lObj_EdtrBtn)

    GrdCntrlMain.RepositoryItems.Add(lObj_RepItm_BtnEdt)

    GrdView.Columns("Select").ColumnEdit = lObj_RepItm_BtnEdt

End Sub

I want to get button at 6th row as highlighted in image.

Let say I want to get this button on CellValueChanged event.

How I can get this button?

回答1:

According to documentation:

Cell values are edited by editors inherited from the BaseEdit class. Once a user starts to edit a cell value, the cell's editor is created. When editing is complete, the cell editor is destroyed. Thus, there can be only one active editor instance at any moment.

So, if you want to get the editor from the cell, you need to focus this cell and start to edit it. Use the ColumnView.FocusedRowHandle property and ColumnView.FocusedColumn property to set the focus on cell and call to GridView.ShowEditor method to invoke the editor. After that use ColumnView.ActiveEditor property to get your editor:

GrdView.FocusedRowHandle = 5 'The 6-th row handle.
GrdView.FocusedColumn = GrdView.Columns("Select")

GridView.ShowEditor

Dim editor = GridView.ActiveEditor