I have custom DataGridView
control and in that control there is RefreshGrid()
method which fill DataGridView
by using DataSource. Now I am tring to remove few columns from that DataGridView
after DataSource binding but unable to remove those, those column not getting removed but add at the end of DataGridView, when I call RefreshGrid()
method again then those column get removed from DataGridView
. Here is code for method RefreshGrid()
public void RefreshGrid()
{
DataTable _table = AccessConnectionManagers.GetDataTableBySQLQuery("select Colm1,Colm2,Colm3 from TableName");
//Data Source Binding with DataGridView
this.DataSource = _table;
if (!string.IsNullOrEmpty("Colm1"))
{
var _colmArray = GridRemoveColumnName.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).Where(a => this.Columns.Contains(a)).Select(a => a).ToArray();
foreach (string colm in _colmArray)
{
//Remove column after Source Binding
this.Columns.Remove(colm);
}
}
}
Call for RefreshGrid()
public Form1()
{
InitializeComponent();
myDataGridView1.RefreshGrid();
}
Please find the error and suggest me the solution.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…