Combo / List in Datagrid

  • Thread starter Thread starter Maria
  • Start date Start date
M

Maria

When adding records through a datagrid I would like one
of the fields only to accept the values 'Yes' or 'No' is
it possible to set this field to some kind of combobox or
list. The datatype for the field in the database is set
to Yes/No and I thought that this may have been directly
translated after binding had taken place but this was not
the case :((

what I ultimately want to do is place a filter on the
records shown in the datagrid based on the result of this
field

I normally develop apps of this nature in Access and have
lost my way here a bit how can I achieve this effect

Maria
 
Maria,
This is tricky but it is do-able. Basically you need to add a
combo box to your form and make it invisible. To add over the current cell
do the following, I dont have full code for you but this should help.


Rectangle rect;

rect = dataGrid1.GetCurrentCellBounds();

comboBox1.Width = rect.Width;

comboBox1.Height = rect.Height;

comboBox1.Left = rect.Left + dataGrid1.Left;

comboBox1.Top = rect.Top + dataGrid1.Top;

comboBox1.Visible = true;

What you then need to do is to update the current cell when the values are
changed in the comboBox. This also needs to be tied into the paint even for
the form because you need to detect which column needs the combo box. And
when shifting from one that does to one that doesent you need to make sure
you repaint to get updated values etc.

Regards - OHM







When adding records through a datagrid I would like one
of the fields only to accept the values 'Yes' or 'No' is
it possible to set this field to some kind of combobox or
list. The datatype for the field in the database is set
to Yes/No and I thought that this may have been directly
translated after binding had taken place but this was not
the case :((

what I ultimately want to do is place a filter on the
records shown in the datagrid based on the result of this
field

I normally develop apps of this nature in Access and have
lost my way here a bit how can I achieve this effect

Maria

Regards - OHM# (e-mail address removed)
 
Oh dear :(( lol

How about a checkbox does that generate the same sort of
problems ?

regards Maria
 
Yes.
OHM#
Oh dear :(( lol

How about a checkbox does that generate the same sort of
problems ?

regards Maria

Regards - OHM# (e-mail address removed)
 
This is not an ADO.NET or WinForms group, I would try a group that is in the
context of your quetion (you will get a better response).

I agree with Maria, just use a Check box if there are only two values.

BTW: Microsoft has an article on their site on how to do exactly what you
want, sorry I dont have the exact link: http://msdn.microsoft.com/
 
Back
Top