Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > ComboBox and ListBox (obsolete as of Q2 2010) > SelectedValue and SelectedItem

Not answered SelectedValue and SelectedItem

Feed from this thread
  • Victoria F avatar

    Posted on Feb 2, 2011 (permalink)

    Hello.

    I have a following problem with the combobox:
    First I initialize my combobbox:  Value column is a numeric field (Int64) , Display column is a Text field:
    ddb_Broker.ValueMember = dtBrokerList.Columns[0].ColumnName;
    ddb_Broker.DisplayMember = dtBrokerList.Columns[1].ColumnName;
    ddb_Broker.DataSource = dtBrokerList.DefaultView;
    ddb_Broker.SelectedItem = null;

    When I retrieve data I need to populate the Broker:
    ddb_Broker.SelectedValue = Convert.ToInt64(gl_dtProgram.Rows[0]["in_broker"]);
    after this line in debugger ddb_Broker.SelectedValue = null ..... ? WHY ?

    Please, help me to set this value. The same story happened with other fields ..

    Thank you ,
    Victoria.

    Reply

  • Victoria F avatar

    Posted on Feb 2, 2011 (permalink)

    I found the problem. It works , but if you use SelectedValue property to set the combobox you have to be aware that this property is very sensitive.
    SelectedValue must be EXACTLY of the same datatype and the same value as values from the ID column.

    If your ID column (ValueMember column) initialized as Int32 but you are trying to assign SelectedValue as Int64 it would not work and vise versa.

    Problems that you might have if your ID column (ValueMember column) is a string: If your SelectedValue that you are assigning has trailing spaces. You have to make sure that you TrimEnd() the value.

    Reply

  • Peter Peter admin's avatar

    Posted on Feb 8, 2011 (permalink)

    Hi Victoria F,

    Thank you sharing this information with us and I am happy to hear that you resolved the issue.
    Do not hesitate to contact us if you have other questions.

    All the best,
    Peter
    the Telerik team
    Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > ComboBox and ListBox (obsolete as of Q2 2010) > SelectedValue and SelectedItem
Related resources for "SelectedValue and SelectedItem"

[ Features | Demos | Documentation | Knowledge Base | Telerik TV | Code Library | Step-by-step Tutorial | Blogs | Self-Paced Trainer ]