views:

267

answers:

4

How to insert a Combobox value in to a database. When i hit Save button in my application, it will stored stored into database like this way..

System.Windows.Controls.ComboBoxItem

What i do for getting correct value of a combo box?

A: 

Hi, lets say your combobox has string items what you need is like this

froeach( ComboBoxItem item in ComboBox1.Items )
{
  string str = (str)item;
 // saving value
}

Best Regards, Iordan

IordanTanev
A: 

This question seems a bit too broad. We are going to need nore information about this to be able to answer this one.

What kind of database are you using? Are you connected to the database or do you need help with tahat as well? In that case there are alot of good reading on the internet to your aid, that I can link to. Do you want to save the ComboBoxItem as an .net object or det values of the item?

The list can go on, you have to give me something more to chew on.

Charlie boy
This should be comment not answer!.
Wael Dalloul
A: 
MyObject obj = myComboBox.SelectedItem as MyObject;

obj.ValueIamInterestedIn; <--- this should be inserted

or if you have string or any valuetype array as ItemsSource then,

myComboBox.SelectedItem.ToString();
Akash Kava
+1  A: 

if you are using a string in the combobox, then you can use the example that Akash Kava showed.

Also, if the combobox contains other elements, you can get those elements through the use of something like

((ComboBoxItem)rpcombo.SelectedItem).Content.ToString()

and casting it to what you need.

Johannes