c# - Export DataGridView SelectedRows to a DataTable -


i want transfer multiple selected rows of datagridview datatable set datasource crystal report.

first load data came database through stored procedure.

datagridview1.datasource = clspayroll.view_employee(); 

then put code below in print selected button multiselection not restricted.

foreach(datagridviewcolumn column in datagridview1.columns) table.columns.add(column.name, typeof(string));  (int = 0; < datagridview1.selectedrows.count; i++) {     table.rows.add();     (int j = 0; j < datagridview1.columns.count; j++) {         table.rows[i][j] = datagridview1[j, i].value;     } } rpt.setdatasource(table); 

i have entries on database here:

emp_id      emp_name    gender   emp-000013  dummy       male     emp-000014  teresa      female   emp-000015  dutcry      male     

when select rows emp-000014 , emp-0000015.

i expect crystalreport viewer list instead shows emp-000013 , emp-000014

thanks posted answers , i'm sorry not update whether i've fixed it.

i able figured out why code not working used be.

instead of fetching data datagridview should use datagridview.selectedrows instead.

here's code

foreach(datagridviewcolumn column in datagridview1.columns) table.columns.add(column.name, typeof(string));  (int = 0; < datagridview1.selectedrows.count; i++) {     table.rows.add();     (int j = 0; j < datagridview1.columns.count; j++) {        table.rows[i][j] = datagridview1.selectedrows[i].cells[j].value;      } } rpt.setdatasource(table); 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -