I’m in the process of upgrading an AddIn and I’ve decided I want to use databinding to ‘make my life easier’ in my windows forms. I’m running into some issues and I’m hoping someone can help me wrap my head around this.
I’m using a DataGridView and I’ve been able to bind textboxes, checkboxes, etc. but I can’t seem to get a combobox to work.
The background info…
The AddIn receives a list of Channels from Vixen. I need to be able to populate the dropdown of the combobox with the Names of the channels. I thought I could just do an items.addrange but that doesn’t seem to be working.
When a user selects the channel name, I need to save either the entire channel object or the channel’s output channel to a custom object in my AddIn so I can use it later. The channel name itself won’t work since it isn’t required to be unique in Vixen.
So, the issue I can’t seem to figure out is how do I bind the dropdown list to the sequence channelname, and the values to be saved to my custom class?
I hope I explained that well enough…
Thanks,
Chris
Also, if I could just get the index of the selected item, that would work for me too.
ctmal wrote:Also, if I could just get the index of the selected item, that would work for me too.
Usually there is a SelectedIndex property or equivalent. (I'm not familiar with DataGridView specifically).
Can you post a sample code snipet?
don
djulien wrote:Usually there is a SelectedIndex property or equivalent. (I'm not familiar with DataGridView specifically).Can you post a sample code snipet?
don
Apparently there isn't a selected index with the datagridviewcombo box...that would make things too easy. I'll post some code later today.
Ok, I think I've got it figured out. For future reference(when I forget how I did it), here's what needed to be done
• Set the DataGridView.Datasource to my custom Object.
• Set the ComboBox.DataPropertyName to “OutputChannel”. This is a property within by custom object…the one that I want written.
• Set the ComboBox.DataSource to the EventSequence.Channels property. This is the 2nd Object that I want to tie my Items to.
• Set the ComboBox.Display = “Name”. this is the name property within the EventSequence.Channels object. It tells the ComboBox to populate the itemList with Names(so the user can understand what they’re looking at).
• Set the ComboBox.ValueMember = “OutputChannel”. This is also a property in the EventSequence.Channels object. It tells the combobox to send the objects OutputChannel instead of it’s name when an item is selected.
So much for making my life easier this time around but it might help down the road.
