开发者

C# add new row to bound datagridview using relations

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 theDataGridView`.


        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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜