BindingList for DTO that maintains the state of remote objects

I have a BindingList for a DTO that can directly bind to a window shape control, and the problem occurs when the user wants to delete a row in my datagridview.

In this situation, the deleted object (row) leaves, and when this DTO BindingList returns to the server for updating, I do not know which row to delete.

Can a BindingList have a collection for the remote object by default or do I need to execute it manually or is there another option for my situation?

Any help would be appreciated.

+3
source share
2 answers

BindingList ListChanged, . , , , .

http://msdn.microsoft.com/en-us/library/ms132742.aspx

, DataGridView.

+1

-, LinQ. DataTable ,

DataTable dt = new DataTable();

        dt.Columns.Add("Want to Delete?",typeof(bool));
        dt.Columns.Add("Data Id", typeof(string));
        dt.Columns.Add("Data 1", typeof(string));
        dt.AcceptChanges();

        return dt;

, .

foreach (var result myResult)

object[] row = new object[]
        {
        false,
        result.Id,
        result.Data1
        };
        dt.Rows.Add(row);

, . bool (checkBox) ,

foreach (DataRow dr in yourDataTable.Rows)
        {
            if (Convert.ToBoolean(dr[0])) // goes in if its checked
            {
                // delete dr[0]
            }
        }

, .

0

Source: https://habr.com/ru/post/1752419/


All Articles