开发者

DataGridView Moving

I am trying to move selected rows from one DGV to another DGV at the click of a button.

I really don't know where to begin..

I 开发者_StackOverflow中文版have two seperate DGVs that are bound by a DataSource..

choiceDGV.DataSource = theChoiceList;
universalDGV.DataSource = theUniversalList;

I would like to move any selected items in the choiceDGV to the univeralDGV by a click of a button. I need to make sure the selected rows are removed from the one DGV and added to the 2nd DGV.

Both of the DataGridView's have the same amount of columns.


Did you try:

foreach (DataGridViewRow row in choiceDGV.SelectedRows)
{
     universalDGV.Rows.Add(row);
     choiceDGV.Rows.Delete(row);
}

or (edited: DataGridViewRow doesn't have ItemArray unfortunately):

foreach (DataGridViewRow row in choiceDGV.SelectedRows)
{
     object[] items = new object [row.Cells.Count];
     for (int i = 0; i < row.Cells.Count; i++)
         items[i] = row.Cells[i].Value;
     universalDGV.Rows.Add(items);
     choiceDGV.Rows.Delete(row);
}


I can't see the issue. You just need move the items you like to the UniversalList within the onclick button handler and call .DataBind() on both the datagridview. In other words you have to hit the lists(datasource) instead of the data grid view

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜