Winform 中listBox 控件的数据源捆绑和选中值读取

捆绑形式

                mylistBox.DataSource = dt.DefaultView;
                mylistBox.DisplayMember = "Text";
                mylistBox.ValueMember = "ID";

获取选中

(单选模式下)

DataRowView item  =   mylistBoxmylistBox.SelectedItem  as  DataRowView;

string strSelectValue = item["ID"].ToString();

(多选模式下)

 foreach (object item in listBTableName.SelectedItems)
                {

                      //  your codes

                }

你可能感兴趣的:(C#(Winform))