I have been wonderinghow to do this ,
microsoft ist currently not encouraging people to use DataSource property. Evenif its existing its not enabled.
#############################################################
BindingSource bs = new BindingSource();
Dictionary<int, String> dicKeyValue = new Dictionary<int, String>();
// Add key, values to the dictionary
while (Reader.Read())
{
dicKeyValue.Add(Convert.ToInt32(Reader["id"]), Convert.ToInt32(Reader["name"]));
}
// Set the datasource of BindingSource
bs.DataSource = dicKeyValue;
cListBox.DataSource = bs;
cListBox.DisplayMember = "Value";
cListBox.ValueMember = "Key";
#############################################################
For getting the Key Values later in code I used KeyValue pairs
var varClickedItem = (KeyValuePair<int, string>)cListBox.Items[intIndex];
//Value
string strClickedUmlaufname = varClickedItem.Value;
//Key
int iClickedUmlaufid = varClickedItem.Key;
microsoft ist currently not encouraging people to use DataSource property. Evenif its existing its not enabled.
#############################################################
BindingSource bs = new BindingSource();
Dictionary<int, String> dicKeyValue = new Dictionary<int, String>();
// Add key, values to the dictionary
while (Reader.Read())
{
dicKeyValue.Add(Convert.ToInt32(Reader["id"]), Convert.ToInt32(Reader["name"]));
}
// Set the datasource of BindingSource
bs.DataSource = dicKeyValue;
cListBox.DataSource = bs;
cListBox.DisplayMember = "Value";
cListBox.ValueMember = "Key";
#############################################################
For getting the Key Values later in code I used KeyValue pairs
var varClickedItem = (KeyValuePair<int, string>)cListBox.Items[intIndex];
//Value
string strClickedUmlaufname = varClickedItem.Value;
//Key
int iClickedUmlaufid = varClickedItem.Key;
Kommentare
Kommentar veröffentlichen