Shaitan00 Posted March 12, 2005 Posted March 12, 2005 --Using [VS C#.NET]-- I have created a structure (struct deviceInfo) that I use to fill a ComboBox (cbTask). So I create a few instantces of deviceInfo and add them to cbTask, I am doing this because the stuct holds other information that on .SelectedItem I wanted to retrieve, question is I have no clue how... It works great in my ComboBox but then how do I access the struct when getting the value? ::CODE:: struct deviceInfo { public int nDevice_ID; public string sDevice_Short; public deviceInfo(int pnDevice_ID, string psDevice_Short) { nDevice_ID = pnDevice_ID; sDevice_Short = psDevice_Short; } } I create an instance of this struct and pass it into my combobox (works great, the combobox with the overloaded .ToString() display the Device_Short string) deviceInfo diInfo = new deviceInfo(ID, Name); cbTask.Items.Add(diInfo); Now later on I want to get the nDevice_ID corresponding to the currently selected item in the combobox. Can I do this (I assume so) but I can't seem to figure out how. Any clues? There has to be a way I can access the struct stored in the combobox so I can extract the Device_ID associated with the selected Device_Short name. Quote
*Experts* Nerseus Posted March 12, 2005 *Experts* Posted March 12, 2005 Try this: deviceInfo selectedDevice = (deviceInfo)cbTask.SelectedItem; Then you can use selectedDevice as a true deviceInfo object. -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.