Is it possible to delete all columns from a datagrid in one delete?
I know that I could loop and delete them one by one, or delete it all and create it.
But you can just clear the columns and leave the grid in place so that users can start a new job. that is, return it to its original state.
Ok here is the code i have
private void PopulateGrid() { UserVGrid.AutoGenerateColumns = false; UserVGrid.Columns.Clear(); List<string> _values = populate.GetVaribles; foreach (var line in _values) { if (!line.Contains("Startind")) { string[] newline = line.Split('='); DataGridViewColumn newColumn = new DataGridViewTextBoxColumn(); newColumn.Name = newline[0]; newColumn.HeaderText = newline[1]; newColumn.ToolTipText = newline[2]; UserVGrid.Columns.Add(newColumn); } }
so suppose _ values โโhave the value apple, pear as values
runs this method once, and I get a datagrid with two columns named apple and pear.
run it a second time this time with _values โโcontaing char, table.
And I ended up with 4 columns of apple, pear, chair and table. What I want, the second time it starts, clears the fist of the grid, and then applies the new columns.
Greetings
Aaron
source share