Mayank Jani

Mayank Jani

  • 1.4k
  • 477
  • 22.7k

How to add new row(s) in a databound datagridview in C# WinA

Sep 30 2019 12:39 AM
Hiii Members,
I am working on a C# WinApp. In a form there are two ComboBoxes and one DataGridView. the first ComboBox contains customer names, the second ComboBox contains products (fruits, vegitables, house holds etc). I have wrote a code that some customers have pre-added products saved in a DataTable so, when I select the customer's name from ComboBox, the pre-saved products automatically loads into the DataGridView.
 
problem is when I try to add a new product for the customer, system throws error, "ColumnCount property cannot be set on a data-bound DataGridView control."
 
when remove the ColumnCount property, it throws another error, "Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound."
 
I have googled many times but no solution working for me. DataGridView.DataSource = null; will not work because I want to add more row in existing (pre-loaded) list.
 
Please show me anyway to add a row in a databound datagridview C# WinApp.
 
Thanks
 
Mayank Jani

Answers (7)