SelectedValue and SelectedItem

3 posts, 0 answers
  1. Victoria F
    Victoria F avatar
    46 posts
    Member since:
    May 2010

    Posted 02 Feb 2011 Link to this post


    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 ,
  2. Victoria F
    Victoria F avatar
    46 posts
    Member since:
    May 2010

    Posted 02 Feb 2011 Link to this post

    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.
  3. DevCraft R3 2016 release webinar banner
  4. Peter
    Peter avatar
    1148 posts

    Posted 08 Feb 2011 Link to this post

    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,
    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.
Back to Top