Combox datagrid with a twist

R

Richard Hallgren

Hi,

In Windows Forms the usual approach to add a combobox in a datagrid involves
adding a single combobox to the DataGrid.Controls, and then selectively
displaying it as needed when a combobox cell becomes the currentcell.
However I'm looking for a way to add a control to a cell in each row from
the actually set up and source binding of the datagrid. I'd like to have the
combobox visible at all times (kind of hard to know that one can change the
values otherwise), the mentioned approach hides the only combobox once the
cell loses focus, to have it ready for display on the next cell that get
focus.

Does anyone have an article about something like this or have a few hints on
how this could be achieved? Preferebly in C#...

Richard
 
Joined
Apr 12, 2006
Messages
2
Reaction score
0
add a combobox in a datagrid at design time

Hi Richard,

you will find your solution by accessing GetCellBounds property of DataGrid Control. You will have to pass row and column in GetCellBounds[row,col] where you want to load the combo box. You will have X, Y, Width and height of that cell. Then you can set Combo Box Bounds property to load combo box at that location.

If you need further help then let me know.

Best Regards,
Dhaval

Richard Hallgren said:
Hi,

In Windows Forms the usual approach to add a combobox in a datagrid involves
adding a single combobox to the DataGrid.Controls, and then selectively
displaying it as needed when a combobox cell becomes the currentcell.
However I'm looking for a way to add a control to a cell in each row from
the actually set up and source binding of the datagrid. I'd like to have the
combobox visible at all times (kind of hard to know that one can change the
values otherwise), the mentioned approach hides the only combobox once the
cell loses focus, to have it ready for display on the next cell that get
focus.

Does anyone have an article about something like this or have a few hints on
how this could be achieved? Preferebly in C#...

Richard
 
Joined
Apr 12, 2006
Messages
2
Reaction score
0
Here is the sample for C#.NET,

X = dataGrid1.GetCellBounds(i,2).X;
Y = dataGrid1.GetCellBounds(i,2).Y;
W = dataGrid1.GetCellBounds(i,2).Width;
H = dataGrid1.GetCellBounds(i,2).Height;

Rectangle rect = new Rectangle( dataGrid1.Left + X - 1, dataGrid1.Top + Y + 1 ,W ,H - 1 );

checkBox.Bounds = rect;
checkBox.BringToFront();
checkBox.Show();

Best Regards,
Dhaval.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top