How can i convert the datagridview.selectedrows to datatable in c




















Add a Solution. So, what exactly is your question? The veracity of your user ID comes immediately into question. Top Rated Most Recent.

Accept Solution Reject Solution. Since you are only transferring selected rows, unless your selection always starts with the first row and has no gaps, you will always get an exception. Instead of using an index, create a new row using DataTable. You can then use the DataRow object to add your cell values.

Posted Nov am OriginalGriff. TheRealProgrammer Nov am. I understand, but how can I implement that? I can't manage to understand how I can integrate this in my for. OriginalGriff Nov am. Create your DataTable then add the columns before the "for" loop - that way you get to give them names which helps. Then inside your "if", create an instance of a DataRow from the DataTable, and use that instance to set the column values in a loop, pretty much as you do now. Then add the row to the table. Habib Habib k 27 27 gold badges silver badges bronze badges.

Thank you Habib, this was very helpfull. AcceptChanges ;. Sunny Patel 7, 2 2 gold badges 30 30 silver badges 42 42 bronze badges. Gopal Gopal 37 5 5 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Then the value from the Name column is fetched.

Finally, the values of the Name column from the selected rows are displayed using MessageBox. ToBoolean row. Cells[ "checkBoxColumn" ]. Value ;. Cells[ "Name" ]. ToString ;. EventArgs Handles btnGet. Cells "checkBoxColumn". If isSelected Then. Cells "Name". End If. Selected Checked row values displayed in MessageBox. Related Articles. Add Comments. Thank you for the feedback.

Answered by:. Archived Forums. Windows Forms Data Controls and Databinding. Sign in to vote. Hi List, I got some selected data rows in a datagridview in c and want to convert them into a datatable, any solution please? SelectedRows thanks Arvin.



0コメント

  • 1000 / 1000