Датагрид Не обновляет индекс - PullRequest
0 голосов
/ 03 октября 2019

У меня есть эта сетка данных с некоторыми данными, и когда я нажимаю одну кнопку, она должна сдвинуть строку вверх или вниз (зависит от кнопки), проблема, с которой я сталкиваюсь. Когда я нажимаю для перемещения, скажем, вниз, первый индекс переходит к индексу 2, а индекс 2 переходит к индексу 1, а пользовательский интерфейс показывает обновленный список, но когда я щелкаю по первой строке, вторая строка выбирается так жепроизойдет, если я нажму второй ряд, первый из которых будет выбран. Ниже мой код:

сетка данных:

         <dg:DataGrid x:Name="data_grid"
                     ItemsSource="{Binding obs_plano_descarga}"                   
                     SelectionEnabled="True"
                     RowHeight="50"
                     HeaderHeight="30"
                     BorderColor="#CCCCCC"
                     HeaderBackground="#5963f7"
                     ActiveRowColor="#8899AA" ItemSelected="Data_grid_ItemSelected"
                     Grid.Column="0" Grid.Row="1">
                    <dg:DataGrid.Resources>
                        <ResourceDictionary>
                            <conv:data_grid_converter x:Key="StreakToColorConverter" />
                        </ResourceDictionary>
                    </dg:DataGrid.Resources>
                    <dg:DataGrid.RowsBackgroundColorPalette>
                        <dg:PaletteCollection>
                            <Color>#F2F2F2</Color>
                            <Color>#FFFFFF</Color>
                        </dg:PaletteCollection>
                    </dg:DataGrid.RowsBackgroundColorPalette>
                    <dg:DataGrid.Columns>

                        <dg:DataGridColumn Title="Comp."
                                           PropertyName="compartimento"
                                           Width="2*"
                                           VerticalContentAlignment="CenterAndExpand"
                                           HorizontalContentAlignment="CenterAndExpand" />

                        <dg:DataGridColumn Title="Prod"
                                           PropertyName="codigo_produto"
                                           Width="2*"
                                           VerticalContentAlignment="CenterAndExpand"
                                           HorizontalContentAlignment="CenterAndExpand" />

                        <dg:DataGridColumn Title="Volume"
                                           PropertyName="volume"
                                           Width="3*"
                                           VerticalContentAlignment="CenterAndExpand"
                                           HorizontalContentAlignment="CenterAndExpand" />

                        <dg:DataGridColumn Title="Posto"
                                           PropertyName="descricao_posto"
                                           Width="5*"
                                           VerticalContentAlignment="CenterAndExpand"
                                           HorizontalContentAlignment="CenterAndExpand" />

                        <dg:DataGridColumn Title="tqe"
                                           PropertyName="seq_tanque"
                                           Width="2*"
                                           VerticalContentAlignment="CenterAndExpand"
                                           HorizontalContentAlignment="CenterAndExpand" />
                    </dg:DataGrid.Columns>
                </dg:DataGrid>

* ItemSelected: *

  private void Data_grid_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            plano_select = (plano_carga_descarga)e.SelectedItem;
            index = e.SelectedItemIndex;
        }

переместить строку к следующему индексу:

 private void Tap_baixo_Tapped(object sender, EventArgs e)
        {
            lista_plano.AddRange(view_model_plano_descarga.local_plano_descarga);
            if (plano_select != null && index > -1)
            {
                var index_plano = lista_plano.IndexOf(plano_select);
                lista_plano.Remove(plano_select);
                lista_plano.Insert(index_plano + 1, plano_select);
                data_grid.SelectedItem = null;
                BindingContext = new view_model_plano_descarga(lista_plano);
            }
        }

view_model:

 public view_model_plano_descarga(List<plano_carga_descarga> plano)
        {
            if (plano != null)
            {
                obs_plano_descarga.Clear();
                for (int i = 0; i < plano.Count; i++)
                {
                    local_plano_descarga.Add(plano[i]);
                }
                local_dados_motorista.Add(local_plano_descarga[0]);
                model_turno turno = new model_turno();
                turno.muda_background(local_plano_descarga[0].turno);
            }
        }

        public static ObservableCollection<plano_carga_descarga> local_plano_descarga = new ObservableCollection<plano_carga_descarga>();

  public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string property)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
        }

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...