I’m using Visual Studio 2010 and I’m making a form using DataGridViewbut I’ve unchecked all Enables for the columns and the rows and I’ve added a button Add New whose idea is to add a new row when is clicked. But I can’t figure out the way to do this.
I’m using Visual Studio 2010 and I’m making a form using DataGridView but I’ve
Share
I think the easyest way is to create a DataTable with the structure you need. Add a DataSet to your project (Project -> Add new item -> DataSet (inside the data section)). In there you can create a DataTable with the structure you need (right click -> Add -> DataTable). Then you can bind the following code to the button you use:
MyDataSet dsMyDataSet = new MyDataSet()dsMyDataSet.MyDataTable[0] = value; // repeat this line for each column, or place it into a loop to do it for you
And then you display your data with this line:
dataGridView1.DataSource = dsMyDataSet.MyDataTable;
This should solve your problem.