Home Forums WinForms controls Xceed Grid for WinForms Detect combobox change

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

    Hi

    I have created a combobox in my grid. How do I detect when a value has been selected / changed so I can act on it.

    Thanks

    Nick Steele

    Imported from legacy forums. Posted by Nick (had 2816 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi

    I am getting closer. I can now trigger an event using

    AddHandler cboItemNum.SelectedIndexChanged, AddressOf Me.ItemChanged

    and

    Private Sub ItemChanged(ByVal sender As Object, ByVal e As EventArgs)

    End Sub

    My problem now is how do I read the contents of the combobox selected.

    Thanks

    Nick Steele

    Imported from legacy forums. Posted by Nick (had 382 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi

    I figured it out thanks if anyone else has the same problem this is how I did it.

    Private Sub ItemChanged(ByVal sender As Object, ByVal e As EventArgs)
    Dim Row As Xceed.grid.DataRow = grdItems.CurrentRow
    Dim strItemNum As String

    ‘exit edit mode if in it
    If CType(grdItems.CurrentRow, Xceed.Grid.DataRow).IsBeingEdited Then
    CType(grdItems.CurrentRow, Xceed.Grid.DataRow).EndEdit()
    End If

    ‘Get the Item Number Selected
    strItemNum = Row.Cells(“ItemNumber”).Value

    End Sub

    Regards

    Nick Steele

    Imported from legacy forums. Posted by Nick (had 444 views)

    User (Old forums)
    Member
    Post count: 23064

    This works, but if you want to get the selected item value event while the editor is active, you can also use the following method, which is in fact the recommended way when using editors in the grid.

    What you need is to use the ActivatingControl and DeactivatingControl events, which are triggered when the editor actually becomes active in the grid (and when it stops being active). You get an handle of the editor in the event, and you can do anything with it, like subscribing to its events. In this example, you subscribe to the SelectedItemChanged event, which will permit you to be notify of any changes while the editor is active.

    e.g. :

    //setup the ComboBoxEditor
    <i> gridControl1.Columns[ “column1” ].CellEditorManager = new ComboBoxEditor( dataSet11.Shippers, “”, “ShipperID”, “%CompanyName%” );
    gridControl1.Columns[ “column1” ].CellViewerManager = new ComboBoxViewer( dataSet11.Shippers, “”, “ShipperID”, “%CompanyName%” );
    </i>
    //subscribe to the events
    <i> gridControl1.Columns[ “column1” ].CellEditorManager.ActivatingControl += new CellEditorEventHandler(CellEditorColumn1_ActivatingControl);
    gridControl1.Columns[ “column1” ].CellEditorManager.DeactivatingControl += new CellEditorEventHandler(CellEditorColumn1_DeactivatingControl);
    </i>

    //Event handlers
    <i>
    private void CellEditorColumn1_ActivatingControl(object sender, CellEditorEventArgs e)
    {
    ( ( WinComboBox )e.Control).SelectedItemChanged += new EventHandler(ComboBoxColumn1_SelectedItemChanged);
    }

    private void ComboBoxColumn1_SelectedItemChanged(object sender, EventArgs e)
    {
    string item = ( ( WinComboBox )sender).SelectedValue.ToString();
    System.Diagnostics.Debug.WriteLine( item );
    }

    private void CellEditorColumn1_DeactivatingControl(object sender, CellEditorEventArgs e)
    {
    </i> //need to unsubscribe to the event, so it does not keep piling up in the ActivatingControl event
    <i> ( ( WinComboBox )e.Control).SelectedItemChanged -= new EventHandler(ComboBoxColumn1_SelectedItemChanged);
    }
    </i>

    Imported from legacy forums. Posted by André (had 3985 views)

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