how to use DisplayMenber in DataReader?

I am using the dataReader but I want to store the ID in something simillar to the ValueMember...




Answer this question

how to use DisplayMenber in DataReader?

  • rob2xx2

    Hi,

    Could you please be more elaborate on this Specifying in detail of your problem would speeden up the process of solving the problem.

    cheers,

    Paul June A. Domag



  • Thomas Edstrom

    Microsoft ComboBox that comes with .NET doesn't support Add method of Items collection with two paramaters value and display member. You can find many third party comboboxes that have such method. When i questioned my self why ComboBox doesn't have such method, i goth an answer that maybe that is intentional and with a purpose. So, let see what that purpose can be. You can connect ComboBox with a source and use it in connected way. You can use DataTable or some Collection class as DataSource. So you will come with an idea of getting that table from database. Not always we create tables for reference data that are used when we need to be able to select a single value from values in comboboxes, radiobuttons, .... So if we create a table in the database we can achieve two goals. First to have a DataTable that can be used as a DataSource in application ComboBox(in this case). But also we can use this table as a foreign key reference, in order to improve referencial integrity of our database.
    Let's see how we can fill ComboBox with data. First we can assume that you will create a method that will read all data from that reference table and return filled DataTable:
    DataTable myTable = GetMyTable();
    //Let's assume that table has two columns, Key column and Description column
    comboOption.DataSource = myTable;
    comboOption.ValueMember = "Key";
    comboOption.DisplayMember = "Description";

    That is all. Now you have a filled combo box. You will read current combobox selection using SelectedValue property.



  • Muhsin Zahid Uğur

    Are you talking about System.Data.DataReader if so it doesnot have any implementaion of Items. Add...

    Your question is not yet clear, Do you want to set an internal Value on each item of Combo Box



  • mobigital

    in the datareader i can just do Items.Add which will add the text to the combobox but i need to add an ID to each item to use when saving to the database just like what i am doing using the ValueMember

  • how to use DisplayMenber in DataReader?