1

I have created a datagridview with 3 columns as below :

  • SR no
  • tasks
  • status(checkbox column)

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.

1 Answer 1

2

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.