Hard-Coding Vs Coding for Dynamic Header

Joined
Feb 21, 2018
Messages
216
Reaction score
86
I want to write C# code to populate the DataGridView (dgv1) "Dynamically"... I mean it would be adaptable to whatever data columns are there in the data source, without any change in the code the data grid view gets updated accordingly...

My current way of doing (is as follows) and I want to remove the hard-coding from it.

void FilldataGridView()
{


List<item> list = SqlCon.Query<item>(RunThis, commandType:
CommandType.StoredProcedure).ToList<item>();

dgv1.DataSource = list;
//dgv1.Columns[0].AutoSizeMode=DataGridViewAutoSizeColumnMode.Fill;
}
class item
{
// i don't like hard-coding in the following lines
public string ItemDesc { get; set; }
public string Category { get; set; }
public int Qty_IN { get; set; }
public int Qty_Out { get; set; }
public int Qty_Bal { get; set; }

}
 
Back
Top