如何在xamarin表单中更新DevExpress CollectionView行?

gzszwxb4  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(82)

我正在开发一个xamarin表单应用程序。我希望用户选择一些值,然后更新collectionview后,显示该行上的选定值。这2是选定的值。它来到这里,但有时福尔斯错误,即“索引”超出范围。必须是非负的,小于集合的大小。参数名称:index'*


的数据

C#代码

ObservableCollection<DynamicReportsParameters> reportsParameters;
public ObservableCollection<DynamicReportsParameters> ReportsParameters
    {
        get
        {
            if (reportsParameters == null)
                ReportsParameters = new ObservableCollection<DynamicReportsParameters>();
            return reportsParameters;
        }
        set => reportsParameters = value;
    } 

void fun () {
                       int ix = 0;

                       if (veri1List[i] != "0")
                        {
                            ix = Int32.Parse(veri1List[i]);
                            
                        }

                            

                        if (ReportsParameters[ix] != null)
                        {
                            Console.WriteLine("veri2 list 0 :" + veri2List[0]);
                            Console.WriteLine("ix :" + ix);


                            DynamicReportsParameters dnp = new DynamicReportsParameters()
                            {
                                ACIKLAMA = ReportsParameters[ix].ACIKLAMA,
                                ACIKLAMA2 = veri2List[0],
                                KODID = ReportsParameters[ix].KODID,
                                ORJVALUE = ReportsParameters[ix].ORJVALUE,
                                PID = ReportsParameters[ix].PID,
                                SECIM = ReportsParameters[ix].SECIM,
                                TYPE = ReportsParameters[ix].TYPE,
                                VIEW_QUERY = ReportsParameters[ix].VIEW_QUERY,
                                VNUMBER = ReportsParameters[ix].VNUMBER,
                            };


                            ReportsParameters.Insert(ix, dnp);
                            ReportsParameters.RemoveAt(ix + 1);

                            //Console.WriteLine("AÇIKLAMA :" + ReportsParameters[ix].ACIKLAMA);
                            //ReportsParameters[ix].ACIKLAMA = "MERT";
                            //Console.WriteLine("AÇIKLAMA :" + ReportsParameters[ix].ACIKLAMA);

                            OnPropertyChanged(); 
}

字符串

XAML代码

<dxcv:DXCollectionView ItemsSource="{Binding ReportsParameters, Mode=TwoWay}"
                               SelectionMode="Single"
                               Margin="8, 2, 8, 2"
                               VerticalOptions="StartAndExpand"
                               TapCommand="{Binding QueryPageOpenCommand}"
                               
                               SelectedItems="{Binding SelectedReportsParameters}"
                       >
            <dxcv:DXCollectionView.ItemTemplate>
                <DataTemplate>
                    <Grid Padding="10, 8, 18, 8">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                            <!--<ColumnDefinition Width="5*"/>-->
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30"/>
                            <!--<RowDefinition/>-->

                        </Grid.RowDefinitions>

                        <Label Text="{Binding ACIKLAMA}"
                                   FontSize="Medium"
                                   Grid.Column="0"
                                   Grid.Row="0"
                                   Margin="0,2"
                                   TextColor="Black"/>

                        <Label Text="{Binding ACIKLAMA2}"
                               FontSize="Medium"
                               Grid.Column="1"
                               Grid.Row="0"
                               Margin="0,2"
                               TextColor="Black" />

                        <Image Source="@drawable/touch.png" HeightRequest="20" Grid.Column="2" Grid.Row="0" />

                    </Grid>
                </DataTemplate>
            </dxcv:DXCollectionView.ItemTemplate>
        </dxcv:DXCollectionView>

lf3rwulv

lf3rwulv1#

关于DXCollectionView的官方文件说:
选择模式=单
当用户选择(点击)一个项目时,SelectedItem属性设置为一个对象,该对象指定与列表中所选项目对应的数据源中的项目。当用户再次点击所选项目时,所选内容将被清除,SelectedItem属性设置为null。若要以编程方式选择项目,将数据源的项对象分配给视图模型的属性,并将SelectedItem属性绑定到它。
因此,您应该将SelectedItems="{Binding SelectedReportsParameters}"更改为SelectedItem="{Binding SelectedReportsParameters}"或将SelectionMode="Single"更改为SelectionMode = Multiple
此外,您可以为selecteditem绑定添加Mode=TwoWay

更新:

使用int value = int.Parse(index)可以将偏好中的index直接转换为int。

相关问题