Home Forums WinForms controls Xceed Grid for WinForms How to add a variable list of icons (that can be clicked) as a column Reply To: How to add a variable list of icons (that can be clicked) as a column

User (Old forums)
Member
Post count: 23064

First, you will need to build your own editor control which can contain as many icons that it needs, and have each of these icon be click-able.  For example, you could have panel (or a user control or whatever else you can think of) containing buttons which have their background image set to one of the icon.

Then you will need to initialize one editor for each cell since it can have varying number of icons/buttons.  You can do that in the AddingDataRow event handler, where you can use the e.DataRow.Cells[ EditorColumn ].CellEditorManager property to set a new editor control each time it is triggered.

Finally, you will need to subscribe to the ActivatingControl and DeactivatingControl event on the CellEditorManager for the column, which will be use to handle the click event on the different icons/buttons.

Here is an example of this with a WinComboBox control :

    private void Form1_Load(object sender, System.EventArgs e)
    {
      gridControl1.Columns[ ComboBoxColumn ].CellEditorManager.ActivatingControl += new CellEditorEventHandler(ComboBoxColumn_ActivatingControl);
      gridControl1.Columns[ ComboBoxColumn ].CellEditorManager.DeactivatingControl += new CellEditorEventHandler(ComboBoxColumn_DeactivatingControl);
    }

    private void ComboBoxColumn_ActivatingControl(object sender, CellEditorEventArgs e)
    {
      ( ( WinComboBox )e.Control).SelectedIndexChanged += new EventHandler(ComboBoxColumn_SelectedIndexChanged);
    }

    private void ComboBoxColumn_DeactivatingControl(object sender, CellEditorEventArgs e)
    {
      //need to unsubscribe to the event, so it does not keep piling up in the ActivatingControl
      ( ( WinComboBox )e.Control).SelectedIndexChanged -= new EventHandler(ComboBoxColumn_SelectedIndexChanged);
    }

    private void ComboBoxColumn6_SelectedIndexChanged(object sender, EventArgs e)
    {
      string index = “index ” + ( ( WinComboBox )sender).SelectedIndex.ToString();
      System.Diagnostics.Debug.WriteLine( index );
    }

 

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