i'm trying to select something inside of my combobox
ex:
cmbDMGCODE.DisplayMember = "Description";
cmbDMGCODE.ValueMember = "DamageCode";
on the description i got the description of the damage but it's value is 41
when ever i will add it in textbox only the displaymember that i got not the number 41 i'm not getting the supposed valuemember of my display.
here's my code
private void LoadDamage()
{
try
{
DataTable dt = bt.GetDamage();
DataRow row = dt.NewRow();
row[0] = "Select Damage";
row[1] = "";
dt.Rows.InsertAt(row, 0);
cmbDMGCODE.DataSource = dt;
cmbDMGCODE.DisplayMember = "Description";
cmbDMGCODE.ValueMember = "DamageCode";
}
catch (Exception ex)
{
throw ex;
}
}
private void btnAddDMG_Click(object sender, EventArgs e)
{
if (cmbDMGCODE.SelectedIndex < 2) { return; }
if (dmgList.Text.Length > 0)
{
string dam = dmgList.Text.Trim() + ",";
string value = Lefts(cmbDMGCODE.Text, Convert.ToInt32(IIf((cmbDMGCODE.Text.IndexOf("(") - 1) > 0, cmbDMGCODE.Text.IndexOf("(") - 1, cmbDMGCODE.Text.Length)));
if (dam.IndexOf(value) < 0)
{
dmgList.Text = dmgList.Text.Trim() + "," + Lefts(cmbDMGCODE.Text, Convert.ToInt32(IIf((cmbDMGCODE.Text.IndexOf("(") - 1) > 0, cmbDMGCODE.Text.IndexOf("(") - 1, cmbDMGCODE.Text.Length)));
}
}
else
{
dmgList.Text = Lefts(cmbDMGCODE.Text, Convert.ToInt32(IIf((cmbDMGCODE.Text.IndexOf("(") - 1) > 0, cmbDMGCODE.Text.IndexOf("(") - 1, cmbDMGCODE.Text.Length)));
}
}
private object IIf(bool expression, object truevalue, object falsevalue)
{
return expression ? truevalue : falsevalue;
}
private string Lefts(string s, int len)
{
return s.Substring(0, len);
}
private string Lefts(string s, int len)
{
return s.Substring(0, len);
}
What I have tried:
i tried to reverse the display and value but as i said only the display i will get in my textbox.