Winform listBox data source in the control and the selected value read bundling

Winform listBox data source in the control and the selected value read bundling

 Bundled form

                dt.DefaultView.Sort ="id DESC";//倒序

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

Getting Selection

(The radio mode)

strSelectValue = String ((the DataRowView) listBTableName.SelectedItem) [ " ID "] .ToString (); // ID field values can be selected where required to obtain their own

(Multiple mode)

 foreach (object item in listBTableName.SelectedItems)
                {

                      // value obtained here according to their processing needs
                    strValue + = ((DataRowView) item ) [ "ID"] ToString () + "|".;

 

                }

Reproduced in: https: //www.cnblogs.com/baishiying/archive/2012/08/29/2662259.html

 Bundled form

                dt.DefaultView.Sort ="id DESC";//倒序

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

Getting Selection

(The radio mode)

strSelectValue = String ((the DataRowView) listBTableName.SelectedItem) [ " ID "] .ToString (); // ID field values can be selected where required to obtain their own

(Multiple mode)

 foreach (object item in listBTableName.SelectedItems)
                {

                      // value obtained here according to their processing needs
                    strValue + = ((DataRowView) item ) [ "ID"] ToString () + "|".;

 

                }

Guess you like

Origin blog.csdn.net/weixin_34405354/article/details/93440117