Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
705
How do I dynamically insert a combo box into a cell?
posted

I have a C# Winforms grid (ultra) that has a drop down in column1.  In column2 there is currently a free form text field.  I need to make it so that if the user selects a certain value from the drop down in column1, it inserts a drop down box into that column2 just for that selected row.  So basically depending on what is selected in column1 the user will have a mix of text fields and drop down boxes in column2.

What even do I trap to make this happen?  Most importantly...what would some code look like?

Thanks in advance for your help.

  • 469350
    Suggested Answer
    Offline posted

    You would set the ValueList property on the cell in the second column of the same row. Make sure you set the ValueList on the cell, not the column, since you only want it to apply on some rows.

    I would recommend that you use two events for this: InitializeRow and CellChange. IntiializeRow will fire for each row in the grid when it is initialized or any time a value in a cell changes. So this will take care of the initial display of the grid.

    The reason you will also want to use CellChange is that InitializeRow won't fire until the user leaves the cell after making a change. So if you want the second cell to update as soon as the user changes something in the first cell, then CellChange will be more responsive.