How can I add a new row in a 开发者_JAVA百科DataGridView
when using relations?
When the DataGridView
is bound to a DataTable
, I can add a row, but when Im using relations, nothing happens, the row won't add to the
DataGridView`.
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("UserName",typeof(string));
ds.Tables.Add(dt);
dataGridView1.DataSource = dt;
DataRow dr = dt.NewRow();
dr["ID"] = 1;
dr["UserName"] = "maxWhite";
dt.Rows.Add(dr);
dataGridView1.DataSource = dt;
before this i use relations, ds.Relations.Add(new DataRelation .......... and after this i can`t add row dataGridView3.DataSource = ds.Tables[0]; dataGridView3.DataMember = "relation_name";
because i must use data binding to filter out my result, eg. i click on parent datagrid 1 and in datagrid 2 i see child rows
e.g. i click in parent grid Ford in child grid shows all Ford models, then on Mazda and so on, and i can`t add row to child grid, because i have relation, when i delete relation all i fine.
精彩评论