PDA

View Full Version : خطای Rows cannot be programmatically added ... when the control is data-bound



fortex
یک شنبه 18 تیر 1396, 08:06 صبح
سلام دوستان وقتی میخام اطلاعات درون یک تکست باکس رو با کد زیر وارد دیتاگیرید ویو کنم:

DataGridViewRow row = new DataGridViewRow();


// create cells
row.CreateCells(this.dataGridView1, roz.Text);


// add to data grid view
this.dataGridView1.Rows.Add(row);

با پیغام زیر مواجه میشم:
Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound

mehliaeb
یک شنبه 18 تیر 1396, 09:27 صبح
DataRow row = dt.NewRow();
row["columnname"]= tbName.Text.toString();
dt.Rows.Add(row);
dt.AcceptChanges();
dataGridView1.DataSource= dt;
dataGridView1.DataBind();