Hi I have database table with 50 columns. Sometimes I need just data form one column, sometimes I need data from all columns. In dbml file columns are called "Properties". According with this first column is property named e.g. X1 last X50. I need data from different numbers of columns - "Properties". In one case only X1,X2,X3, in another X15,X16,X17,X18 etc.
I do not want to write a lot of code (a lot of if statements) to solve this problem. so my question is:
Is possible to use loop to work with data form different properties (columns)?
Shahan AyyubPosted Dec 19, 2010, 5:33 PM
Do you bind data with DataGridView then you can set Visible property like this:
dataGridView1.Columns[0].Visible = true;
when you will bind call a method HideAllColumns()
which will do this:
public void HideAllColumns(bool b)
{
foreach (DatagridViewColumn c in dataGridView1.Columns)
dataGridView1.Columns[0].Visible = b;
}
then manually allow visibility to those columns which you want to show like:
dataGridView1.Columns[2].Visible = true;
dataGridView1.Columns[3].Visible = true;
dataGridView1.Columns[14].Visible = true;
dataGridView1.Columns[50].Visible = true;
etc....