none
Como popular um DataTable como diferentes listas e uma coluna de checkbox RRS feed

  • Question

  • Hello guys, I need some help in C #.

    I would like to populate a DataTable as follows:
    In the first column enter the data in a list;
    In the second column enter the data of the second list;
    In the third column checkboxes acorco enter the number of rows in the first list.

    Sincerely,

    Eduardo
    Thursday, September 5, 2013 3:30 PM

Answers

  • I think you want to use a DataGridView object in a form project.  A DataTable is not a form object and the user won't be able to see the checkboxes.  A DataGridView you will be able to add a checkbox column for the user to select rows of the DataGridView.  You can then write a function to move the check rows of the DataGridView into a DataTable.

    Below is an example of adding a List<string> to a DataTable

                DataTable table = new DataTable();
                DataRow newRow;
                table.Columns.Add("ColA", typeof(List<string>));
                table.Columns.Add("ColB", typeof(List<string>));
                newRow = table.Rows.Add();
                newRow["ColA"] = new List<string>() { "A", "B", "C" };
                newRow["ColB"] = new List<string>() { "D", "E", "F" };


    jdweng

    • Proposed as answer by Damon Bu - MSFT Wednesday, September 11, 2013 5:15 AM
    • Marked as answer by Damon Bu - MSFT Thursday, September 12, 2013 7:58 AM
    Sunday, September 8, 2013 12:10 PM

All replies

  • Hi,

    Could you please describe the issue clearly in english? thanks.

    Regards


    ALL FOR ONE AND ONE FOR ALL.

    Sunday, September 8, 2013 10:28 AM
  • I think you want to use a DataGridView object in a form project.  A DataTable is not a form object and the user won't be able to see the checkboxes.  A DataGridView you will be able to add a checkbox column for the user to select rows of the DataGridView.  You can then write a function to move the check rows of the DataGridView into a DataTable.

    Below is an example of adding a List<string> to a DataTable

                DataTable table = new DataTable();
                DataRow newRow;
                table.Columns.Add("ColA", typeof(List<string>));
                table.Columns.Add("ColB", typeof(List<string>));
                newRow = table.Rows.Add();
                newRow["ColA"] = new List<string>() { "A", "B", "C" };
                newRow["ColB"] = new List<string>() { "D", "E", "F" };


    jdweng

    • Proposed as answer by Damon Bu - MSFT Wednesday, September 11, 2013 5:15 AM
    • Marked as answer by Damon Bu - MSFT Thursday, September 12, 2013 7:58 AM
    Sunday, September 8, 2013 12:10 PM