none
ListBox怎么设置DisplayMember? RRS feed

答案

  • Hi 

    看列子吧: http://msdn.microsoft.com/en-us/library/system.windows.forms.listcontrol.displaymember.aspx 

    // Populate the list box using an array as DataSource.
                ArrayList USStates = new ArrayList();
                USStates.Add(new USState("Alabama", "AL"));
                USStates.Add(new USState("Washington", "WA"));
                USStates.Add(new USState("West Virginia", "WV"));
                USStates.Add(new USState("Wisconsin", "WI"));
                USStates.Add(new USState("Wyoming", "WY"));
                ListBox1.DataSource = USStates;

    // Set the long name as the property to be displayed and the short 
                // name as the value to be returned when a row is selected.  Here 
                // these are properties; if we were binding to a database table or 
                // query these could be column names.
                ListBox1.DisplayMember = "LongName";
                ListBox1.ValueMember = "ShortName";


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2013年6月18日 3:23
    版主