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

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

    I have a requirement to have a single column that displays a variable list of icons (or small images) that can be clicked.  I would need to know which icon was clicked.

    What is the best way to do this?

    Thanks,

    Bernie

    Imported from legacy forums. Posted by Bernard (had 2049 views)

    User (Old forums)
    Member
    Post count: 23064

    Do you mean there is a list of icons within each cell, or each cell has only one icon?  If the later, you can simply use the CurrentCellChanged event on the GridControl, and in the event handler, simply verify which icon is associated to this cell.

    If the previous, can you provide more details on how you set up this column and the viewer you are using inside it?

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

    User (Old forums)
    Member
    Post count: 23064

    The want a variable list of “command” icons for the various things you can do depending on what is in the row in a single column (other wise there would be to many columns if there was a separate column for each command type.

    Imported from legacy forums. Posted by Bernard (had 1773 views)

    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)

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