N
N
nnmnews2013-07-27 12:17:16
.NET
nnmnews, 2013-07-27 12:17:16

Deleting a row in a DataGrid?

I am learning C#. The question arose, how to remove a row from the DataGrid?

public class Wrapper
    {
        public List<ApiFormatGetAllPerson> apidata { get; set; }
    }


    public class ApiFormatGetAllPerson
    {
        public string id { get; set; }
        public string name { get; set; }
        public string datebirth { get; set; }
        public string card { get; set; }
        public string email { get; set; }
        public string phone { get; set; }
    }

var js = "{\"ApiData\":" + json + "}";
            Wrapper w = new JavaScriptSerializer().Deserialize<Wrapper>(js);
            dg.ItemsSource = w.apidata;

I receive an index of the selected line so
int i = dg.SelectedIndex;
Actually how to delete a line from DataGrid?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2013-07-27
@nnmnews

If List is replaced by ObservableCollection, then when deleting from the collection, the string will also be deleted from the DataGrid.
Or another (bad) option. After removing from the list, call dg.Items.Refresh(), but this will cause all rows to be updated.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question