c# - Deleting rows in a datagrid -
I have recently moved from WinForms to WPF and it seems that it is more complicated to deal with datagrids. . . Data grid x; I have done the XAML code following the DataGridAdd" HorizontalAlignment = "Left" margin = "591,360,0,0" VerticalAlignment = "top" height = "118" width = "202" AutoGenerateColumns = "false" ScrollViewer.CanContentScroll = "false" VerticalScrollBarVisibility = "Disabled" grid. Column = "1" canuser diameter = "true" & gt; & Lt; DataGrid.Columns & gt; & Lt; DataGridTextColumn = Binding "{Binding Varenr}" ClipboardContentBinding = "{x: Nulled}" Header = "Vare Nr .:" width = "100" /> & Lt; DataGridTextColumn binding = "{binding antal}" clipboard contentbinding = "{x: ft}" header = "antal" width = "100" /> & Lt; /DataGrid.Columns> & Lt; / Data grid & gt; and background code: The issue is that, when I am adding data to a row and pressing the print button, it removes the expected objects: < P> The problem occurs when I use several rows Adding: while The loop gets infinite, because the DataGridAd.Eight. In this case the value is not less than "2". How can I handle this problem? For example, if you have more than 2 items in the DataGrid Ad, for example, if you have more than 2 items in the Data Grid Ad, So your code will be excited like this: Then, the DataGrid Ad.its.Count Value does not go below "2" By the way, why use this? Update: To run this code, and you
& lt :: name = "When I run the application manually in the datagrid from the user interface to the datagrid
public partial squares window 1: window {observable collection & lt; Add & gt; List; Public Window 1 () {InitializeComponent (); List = New Observational Collection & lt; Add & gt; (); DataGridAdd.ItemsSource = List; } Add public category {public string Varenr {get; Set; } Receive public string {receive; Set; }} Add Private Zero Button Print Clip (Object Sender, RoutedEventArgs e) addval = DataGridAdd.SelectedItem Add; While (DatagreatsAd.Entimes.Count & gt; 1) {string vare = addval.Varenr; Wire antal1 = addval.Antal; List.Remove (addval); }}}
dataGridAdd.SelectedIndex = -1 and < After the code> Data Grid Ad.itedEdit = empty list. Remove (adwale); So, if you remove again, this flat will return.
Private Zero Button_Click (Object Sender, RoutedEventArgs e) [Addval = dataGridAdd.SelectedItem Add as add; Console.WriteLine (dataGridAdd.SelectedIndex); Console.WriteLine (dataGridAdd.SelectedItem); String vare = addval.Varenr; Wire antal1 = addval.Antal; List.Remove (addval); Console.WriteLine (dataGridAdd.SelectedIndex); Console.WriteLine (dataGridAdd.SelectedItem); }
Comments
Post a Comment