I am trying to set the Text
property of ComboBox on the basis of SelectedIndex but the problem is Text
is becoming String.Empty
after changing the Index of Combobox.
Each Item in ComboBox correspond to a string in DataTable
having 2 columns Name
, Description
What i need is when users select's a Name (Index Changes) when i want to show the Description of that in ComboBox
What i have tried :
private void tbTag_SelectionChangeCommitted(object sender, EventArgs e)
{
// get the data for the selected index
TagRecord tag = tbTag.SelectedItem as TagRecord;
// after getting the data reset the index
tbTag.SelectedIndex = -1;
// after resetting the index, change the text
tbTag.Text = tag.TagData;
}
How i have populated the Combobox
//load the tag list
DataTable tags = TagManager.Tags;
foreach (DataRow row in tags.Rows)
{
TagRecord tag = new TagRecord((string)row["name"], (string)row["tag"]);
tbTag.Items.Add(tag);
}
Helper Class Used :
private class TagRecord
{
public TagRecord(string tagName, string tagData)
{
this.TagName = tagName;
this.TagData = tagData;
}
public string TagName { get; set; }
public string TagData { get; set; }
public override string ToString()
{
return TagName;
}
}