c# read specific columns from excel file

Viewed 32

i have a tables like this

enter image description here

and i added checkboxs elements to form like this

enter image description here

i want to add the checkbox element text to datagridview then read the checked columns from excel file

if Date, Time, Price are checked datagridview will be like this

enter image description here

then get full Date column from excel file and add it to Date column in datagrid

my code to add checked boxes text as a columns in datagridview

DataTable dt = new DataTable();
    foreach (Control checkbox in pnl.Controls)
        if (checkbox.GetType() == typeof(CheckBox) && ((CheckBox) checkbox).Checked)
        {
            string txt = ((CheckBox)checkbox).Text;
            dt.Columns.Add(new DataColumn(txt, typeof(object)));
        }
datagrid.DataSource = dt;
0 Answers
Related