kranthi4uonly
asked on
combo box in c# windows form
i had a combo box the field length of it is 1 char in database but the user should be able to see "default " and "override" text in combobox
so how can i set the properties for that or how can i do it manualy please help me .
or else how i will store it in the collection so that it should be 1 char in storage but the displaymember should be overide or default
so how can i set the properties for that or how can i do it manualy please help me .
or else how i will store it in the collection so that it should be 1 char in storage but the displaymember should be overide or default
ASKER
hi
can't we set them in the properties of the "combo box" i mean presing f4 not this properties
if not
coming to my question
the values doesn't exist in the database if i select "default" or "override" {and submits form) it should go as 1 char to the database but it should be dispalyed as "default" or "overide" in combobox
thanks regards
can't we set them in the properties of the "combo box" i mean presing f4 not this properties
if not
coming to my question
the values doesn't exist in the database if i select "default" or "override" {and submits form) it should go as 1 char to the database but it should be dispalyed as "default" or "overide" in combobox
thanks regards
Typically, you do this by having a datasource that contains both the single character value and the display value.
Let's say you have a set of rows in this form, with a column for "DisplayValue" and a column for "DataValue", in a view called dvChoices.
Try:
choiceCombobox.DataSource = dvChoices
choiceCombobox.DisplayMemb er = "DisplayValue";
choiceCombobox.ValueMember = "DataValue";
David
Let's say you have a set of rows in this form, with a column for "DisplayValue" and a column for "DataValue", in a view called dvChoices.
Try:
choiceCombobox.DataSource = dvChoices
choiceCombobox.DisplayMemb
choiceCombobox.ValueMember
David
that is what my post will do.-- it creates an array list with text that you will assign to whatever character you want.-- the arraylist becomes your datasource after you construct it. the valuemember is what gets saved to the database the display member is what is displayed to the user
ASKER
hi davis
where to set this one in ur solution is it in the properties or what
cmb.datasource = al;
cmb.displayMember = "text";
cmb.ValueMember = "value";
and one more thing is iam using menu -->data--->datasources and if u do show datasources u wil get all the colum names of the datatable so i selected combobox for that colum and draged it on form so automaticaly it will bind to the colum so how to do it fmr here please help me
where to set this one in ur solution is it in the properties or what
cmb.datasource = al;
cmb.displayMember = "text";
cmb.ValueMember = "value";
and one more thing is iam using menu -->data--->datasources and if u do show datasources u wil get all the colum names of the datatable so i selected combobox for that colum and draged it on form so automaticaly it will bind to the colum so how to do it fmr here please help me
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ArrayList al = new ArrayList();
al.Add(new DisplayValues("text to display", <value from db>);
public class DisplayValues
{
private String displaytext;
private Int32 dbvalue;
public DisplayValue(String text, Int32 value)
{
displaytext = text;
dbvalue = value;
}
public String DisplayText
{
get { return displaytext; }
set {displaytext = value; }
}
public Int32 DBValue
{
get { return dbvalue; }
set { dbvalue = value; }
}
}
then the combobox datasource can be set to this for display member and value member.
cmb.datasource = al;
cmb.displayMember = "text";
cmb.ValueMember = "value";
forgive me if this doesn't work out of the box but i am posting quickly. it should at least get you off on the right foot.