C1ComboBox Setting with ItemsDataSource , ItemsDisplayMember, ItemsValueMember

Originally Posted 28 February 2017, 5:19 am EST

  • Originally Posted 28 February 2017, 5:19 am EST

    Hello everyone. I have a table tbl_Nationality with 2 fields ID and NameEN in Sql Server. I bind it to C1ComboBox using Linq, and I want to display a country(index 5) as default when first load. Here is my code:

    SHDataContext db = new SHDataContext();
    cboNationality.ItemsDataSource = (from s in db.tbl_Nationalities select s).ToList();
    cboNationality.ItemsDisplayMember = "NameEN";
    cboNationality.ItemsValueMember = "ID";
    cboNationality.InitialSelectedIndex = 5;

    I have 2 troubles: it does't show the name of country(index 5) when first load. And when event SelectedItemChanged occur, instead of display NameEN, the c1combobox display ID of that country.(see attach picture). Any suggestions? Thanks you.

  • Reply


    Thanks for providing the code snippet and screenshot.

    In order to set the index of the item which you want to display by default you need to set the SelectedIndex property of the C1ComboBox.
    cboNationality.SelectedIndex = 5;

    Furthermore, to display the content of the column which is set in ItemsDisplayMember in the text portion of the C1ComboBox you need to set TextDetached property of it to true.
    cboNationality.TextDetached = true;

  • Marked as Answer


    It works. Many thanks Akshay.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels