Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

How to save add/remove column in datagridview in C# winform

$
0
0

Hi All,

Need your help.

>> I created dataTable and attached to the datagridview.

>> It has got 4 columns.

tempTable.Columns.Add("DisplayName");
            tempTable.Columns.Add("SamAccountName");
            tempTable.Columns.Add("PrimarySmtpAddress");
            tempTable.Columns.Add("Identity", typeof(int));

dataGridView1.DataSource = tempTable;

>> I'm allowing the users to choose the column to show/hide by displaying list of columns in sel form.

 TableColumnCollection = tempTable.Columns;
            foreach (DataColumn Column in TableColumnCollection)
            {
                comboBox1.Items.Add(Column.ColumnName);
            }



            frmColFilter sel = new frmColFilter();

            sel.SetSourceColumns(TableColumnCollection);
            sel.ShowDialog();
            CheckedColumns = sel.GetSelectedColumns();
            SetTableBySelectedCoulmns();

>> Hiding/showing column works fine, i do not know how to save the changes and use it again when the application starts .

>> Lets say user wants only to show displayname, samaccountname. He will use the sel form to hide other columns.Once he is done, all works fine. But if he closes the tool and starts again, it will display the previously hidden columns also because I do not have to save the column change details and reuse it.

>> Please help me with the sample to save the change and reuse it when the application starts.

Thank you.


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>