Set the value of a combobox in a cell from a button click event

Sep 26, 2009 at 2:16 PM

Hi All,

I am creating an application to communicate with embedded devices.

In one of the configuration screens I have a grid filled with comboboxes. One row holds 6 comboboxes.

When the user sets the value of the first combobox in a row, the possible values of the other 5 are known and I configure them accordingly.

To achieve that, I use a "OnValueChanged" event on the grid.

So far so good.

 

Now, when the program starts, the grid needs to get prefilled with values from the device.

When I set the value of the first combobox in the row, I expected the "OnValueChanged" event to fire but .... it does not.

So I created a button on the form to test this and I am now trying to set the values of the comboboxes in the grid from the button click event.

Still without success.

 

Has anyone done this?

Or has anyone some ideas on this?

 

Thank you,

 

Leon

 

Sep 26, 2009 at 2:27 PM

Hi All,

 

I can also add that the changes I make from the button click event do not show in the grid though I can see by debugging that the combox has been updated as intended.

The value of the cell however is not updated. I have tried invalidating and calling update without success.

 

Leon

 

Sep 26, 2009 at 3:21 PM

Hi All,

 

Here is some example code.

Take example no 3 from the Windows forms samples that come with sourcegrid.

Add the following lines to the event procedure CellButton_Click that handles the click event for the "smily" button on example 3

 

SourceGrid.Grid grid = (SourceGrid.Grid)context.Grid;
SourceGrid.Cells.Editors.ComboBox cbEvent = (SourceGrid.Cells.Editors.ComboBox)grid[30, 1].Editor;

cbEvent.Control.Text = "Value 2";
grid.InvalidateCell(new SourceGrid.Position(30, 1));
context.Grid.Update();

These lines are supposed to change the value of the "Inline combobox" several lines above the button.

Alas, it does not show!

I hope there is somebody who knows how to do it.

 

Leon

Sep 26, 2009 at 3:44 PM

Hi All,

 

I figured it out.!!!

You not only have to set the combobox but also the cell value.

So add 1 line to the code above and it becomes

SourceGrid.Grid grid = (SourceGrid.Grid)context.Grid;
SourceGrid.Cells.Editors.ComboBox cbEvent = (SourceGrid.Cells.Editors.ComboBox)grid[30, 1].Editor;

cbEvent.Control.Text = "Value 2";

grid[30,1].Value = "Value 2";
grid.InvalidateCell(new SourceGrid.Position(30, 1));
grid.Update();

Leon

 

Coordinator
Sep 27, 2009 at 7:33 AM

Great you've figured it out ;)