Reputation: 653
I have created a datagridview with 3 columns as below :
I have to add 11 rows whose values I want to hardcode. like sr no 1 to 11 and specific texts for tasks. checkbox column should be initially all set to false.
what is the best way of doing it? please help.
Upvotes: 1
Views: 123
Reputation: 292715
When working with a DataGridView
, I usually prefer to define the content using databinding. A simple way is to create a class to represent your records, create a list of objects of this class, and assign it to the DataSource
property of the DGV :
class SR
{
public int SRNumber { get; set; }
public string Tasks { get; set; }
public bool Status { get; set; }
}
...
var list = new List<SR>
{
new SR { SRNumber = 1, Tasks = "Foo", Status = true },
new SR { SRNumber = 2, Tasks = "Bar", Status = false },
...
};
dataGridView.DataSource = list;
In the designer, don't forget to map each column to a property of the SR
class (set DataPropertyName
to the name of the property)
Upvotes: 2