Scenes
Use NPOI import Excel and assigned to the DataTable, and then displayed on DataGrdView, and add a check box, and then get the contents of the selected row.
Winform NPOI use Excel to import and implement assigned to the DataTable:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100064821
effect
achieve
In the above has been successfully imported and assigned to on the basis of DataTables, add checkbox on DataGridView.
The following code is added to the click event of the second button, the data source to generate the title dataTable add a multiple choice list.
DataGridViewColumn checkCol = new DataGridViewCheckBoxColumn(); this.dataGridView1.Columns.Add(checkCol);
Then click on the event's third button
Private void the button4_Click ( Object SENDER, EventArgs E) { int strCount = 0 ; // firstly acquired in the first cycle of the selected number of rows for ( int I = 0 ; I <dataGridView1.Rows.Count; I ++ ) { // if It is selected IF (( BOOL ) dataGridView1.Rows [I] .Cells [ 0 ] == .EditedFormattedValue to true ) { strCount ++ ; } } // array to store the new length of each selected row String [] = STR new new String [strCount]; for ( int I = 0 ; I <dataGridView1.Rows.Count; I ++ ) { IF (( BOOL ) dataGridView1.Rows [I] .Cells [ 0 ] == .EditedFormattedValue to true ) { // get the first cell of the current row + @ + content of the second cell STR [I] = dataGridView1.Rows [I] .Cells [ . 1 ] .Value.ToString () + " @ " + dataGridView1.Rows [I] .Cells [ 2 ] .Value.ToString (); } } // output the contents of all rows selected for ( int I = 0 ; I <str.length; I ++ ) { MessageBox.Show ( String .Format ( " acquired as the {0}: " , I + . 1 ) + STR [ I]); } }
Sample code download
https://download.csdn.net/download/badao_liumang_qizhi/11612423