2
   RDP0 yeni = new RDP0();
        yeni.IPADDRESS = "1.1.1.1";
        yeni.PASSWORD = " 10akh0";
        yeni.NO = 8;
        yeni.CUSTID = 1000;
        testList.Add(yeni);
        dataGridView1.DataSource = testList;

I'm getting data-bound error therefore I cannot add rows. Any help would be great. This is how I bound data to my dataGV:

        tm = new testModel();
        var query = from fe in tm.ERDP0 select fe;
        testList = query.ToList();
        dataGridView1.DataSource = testList;
0

1 Answer 1

3

If the DataGridView is data bound you cannot add new rows/columns to the DataGridView directly. But you could add a row to a DataTable which will update your DataGridView automatically.

DataTable dt = dataGridView1.DataSource as DataTable;
dt.Rows.Add("new row");

Or you could add the new row to your source list and then reset the DataSource:

testList.Add(youritem);
dataGridView1.DataSource = null;
dataGridView1.DataSource = testList;
Sign up to request clarification or add additional context in comments.

3 Comments

I'm gettin 1 more error now . "object reference not set to an instance of an object" ` DataTable dt = dataGridView2.DataSource as DataTable; using (DataGridViewRow row = new DataGridViewRow()) { row.CreateCells(dataGridView2); dt.Rows.Add(row); } dataAdapter.Fill(dt); ` @Roman
private List<RDP0> testList = new List<RDP0>(); rdp0 is the name of the table from my Database
with your help I find the solution to my problem thanks

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.