RadDropDownList Selected Value

10 posts, 1 answers
  1. Robert
    Robert avatar
    53 posts
    Member since:
    Feb 2010

    Posted 21 Oct Link to this post

    Hi,

    Inthat scenario, when I try to edit the selected item, you'll see thelist.Selected Value is not changed.
    But if you press button to get the Selected Value, you'll it's already = null.

    It should keep the selected value, because it's needed to update data (text), using the id as value in a DB table..

    public partial class RadForm2 : Telerik.WinControls.UI.RadForm
    {
         
        RadDropDownList list = new RadDropDownList();
        TextBox tb = new TextBox();
        Button b = new Button();
     
        public RadForm2()
        {
            InitializeComponent();
            this.Controls.AddRange(new Control[] { list, tb, b });
     
            list.DropDownStyle = RadDropDownStyle.DropDown;
            list.Location = new Point(30, 30);
            list.Width = 100;
            list.Height = 25;
            list.DisplayMember = "name";
            list.ValueMember = "id";
            list.NullText = "not selected";
            list.SelectedValueChanged += list_SelectedValueChanged;
     
            tb.Location = new Point(30, 70);
            tb.Width = 100;
            tb.Height = 25;
     
            DataTable dt = new DataTable();
            dt.Columns.Add("id", typeof(int));
            dt.Columns.Add("name", typeof(string));
     
            dt.Rows.Add(1, "one");
            dt.Rows.Add(2, "two");
            dt.Rows.Add(3, "three");
            dt.Rows.Add(4, "four");
            dt.Rows.Add(5, "five");
            list.DataSource = dt;
     
            b.Location = new Point(30, 110);
            b.Width = 100;
            b.Height = 25;
            b.Text = "Get Selected Value";
            b.Click += b_Click;
        }
     
        void b_Click(object sender, EventArgs e)
        {
            tb.Text = list.SelectedValue + " <----> " + list.SelectedText;
        }
     
        void list_SelectedValueChanged(object sender, EventArgs e)
        {
            tb.Text = list.SelectedValue + " <----> " + list.SelectedText;
        }
    }

     

  2. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 21 Oct Link to this post

    Hi,

    Thank you for writing.

    I have tested this with the latest version and the behavior is correct on my side. With which version are you testing this? I have attached a small video as well. 

    I am looking forward to your reply.
     
    Regards,
    Dimitar
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Robert
    Robert avatar
    53 posts
    Member since:
    Feb 2010

    Posted 21 Oct in reply to Dimitar Link to this post

    Ok, what if I want to Update the Name of the Selected ID in a Database?

    ----> create table aTable (ID int, NAME varchar )

    DataTable dt = .. select * from aTable

    RDlist.DataSource = dt;

    RDlist.ValueMember = name
    RDlist.DisplayMember = name

    If I need to update the name with UPDATE button, then I select the item and update its name.

    Then I expect the SelectedValue is still the ID of the item.

    And I just use update aTable set name=list.Text where id=SelectedValue

    I have been doing that way for ages :)

    In that scenario that you have, I must each time keep the previously selected value and use it when need to update.

  5. Robert
    Robert avatar
    53 posts
    Member since:
    Feb 2010

    Posted 21 Oct in reply to Dimitar Link to this post

    When I want to add a new record, then I just don't mind what is in SelectedValue and add new record with new Name value.
  6. Robert
    Robert avatar
    53 posts
    Member since:
    Feb 2010

    Posted 21 Oct in reply to Robert Link to this post

    sorry in previous RDlist.ValueMember = id

    good if EDIT would be added to post div

  7. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 24 Oct Link to this post

    Hello Robert,

    I still don't understand which is the exact behavior that you want to avoid. Could you please send me the code that you are using for the update and specify the exact moment where the index is not valid? 

    Thank you in advance for your patience and cooperation. 

    Regards,
    Dimitar
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  8. Robert
    Robert avatar
    53 posts
    Member since:
    Feb 2010

    Posted 23 Nov in reply to Dimitar Link to this post

    In case of when DataSource is a table lime I said with id&value you would consider the scenario when it used to update the data in table/
    Let's say we have a simple table:

    DIC_COMPANY
    ID     |    NAME
    =====================
    11         Telerik Co.
    12        Microsoft Inc.
    13        ITBRIGADA Inc.

    When such table is loaded, then the value is ID and the dataText - NAME

    When a user selects one of the items, it supposed that the ID value in SelectedValue
    Then user would like to rename the company name fromTelerik Co. to Telerik Corp.
    If the SelectedValue contains its ID then it's easy to get all data to do the update DML command.
    ID is in SelectedValue and the new name in Text..

    Got My idea?

    In 2012 it was like that, and it was perfect.

  9. Robert
    Robert avatar
    53 posts
    Member since:
    Feb 2010

    Posted 23 Nov in reply to Robert Link to this post

    Just have a look.. what is most convenient way for a prigrammer, when SelectedValue is = id or NULL?

    For me the SelectedValue is = id is obviously the best.

  10. Answer
    Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 23 Nov Link to this post

    Hello Robert,

    I understand your scenario now. You can just set the SyncSelectionWithText property and then you will get the correct index:
    list.DropDownListElement.SyncSelectionWithText = false;

    I hope this will be useful. 

    Regards,
    Dimitar
    Telerik by Progress
    Telerik UI for WinForms is ready for Visual Studio 2017 RC! Learn more.
  11. Robert
    Robert avatar
    53 posts
    Member since:
    Feb 2010

    Posted 23 Nov in reply to Dimitar Link to this post

    Wow!!! Cool :) 

    Lot of respect!!

Back to Top
UI for WinForms is Visual Studio 2017 Ready