Windows Develop Bookmark and Share   
 index > Windows Forms General > to get first value of combobox.
 

to get first value of combobox.

hi!
(language :c#)
i am in big trouble..
i have a combobox in which i am getting through database.
now after binding it i need to get the first value of it i.e., the value of index=0 but i am not getting it.

my code goes like this::
SqlConnection con1 = new SqlConnection("data source='.\\sqlexpress';database=gimage;integrated security=true;");
            SqlCommand com1 = new SqlCommand("select * from cropSize");
            SqlDataAdapter adp1 = new SqlDataAdapter();
            DataSet ds1 = new DataSet();
            com1.Connection = con1;
            adp1.SelectCommand = com1;
            adp1.Fill(ds1);
            cmbSelectedCropBoxSize.DataSource = ds1.Tables[0];
            cmbSelectedCropBoxSize.SelectedIndex = 0;

now after this if i do
string txt;
txt = cmbSelectedCropBoxSize.SelectedItem.ToString();

i am getting System.Data.DataRowView


if i do the following i am getting nothing.
 txt = cmbSelectedCropBoxSize.SelectedText.ToString();

what should i do now..please help me out!!

nandini
NandiniP  Wednesday, September 16, 2009 8:04 AM


use


txt =cmbSelectedCropBoxSize.Items[0].ToString()

Bharath kumar Y.S  Wednesday, September 16, 2009 8:46 AM
just a note :
add this condition also

if(cmbSelectedCropBoxSize.Items.Count > 0)
txt = cmbSelectedCropBoxSize.Items[0].ToString();
Paras
paras kumar  Wednesday, September 16, 2009 9:29 AM


use


txt =cmbSelectedCropBoxSize.Items[0].ToString()

Bharath kumar Y.S  Wednesday, September 16, 2009 8:46 AM
just a note :
add this condition also

if(cmbSelectedCropBoxSize.Items.Count > 0)
txt = cmbSelectedCropBoxSize.Items[0].ToString();
Paras
paras kumar  Wednesday, September 16, 2009 9:29 AM
hi!
thanks for ur reply but
this way i am getting -1

nandini
NandiniP  Wednesday, September 16, 2009 11:36 AM

is the problem solved ..if notcan you give discriptionof the problem what that -1 is..

Bharath kumar Y.S  Wednesday, September 16, 2009 11:42 AM
Are you saying that cmbSelectedCropBoxSize.Items[0].ToString(); is returning -1??
Paras
paras kumar  Wednesday, September 16, 2009 1:07 PM

You can use google to search for other answers

Custom Search

More Threads

• Passing Data Between Forms
• Test if a mysettings.value exists / is defined, How?
• Visual Basic.net Standard Edition
• Editing property of type List in designer
• How do you use the PropertyDescriptorCollection?
• ToolTip
• treeview control
• Best practices for Prototyping applications in .NET
• TreeView presentation
• User Control Load event