XAML 如何获取SfDataGrid控件中CellLongPress事件的e.RowColumnIndex的值?

n6lpvg4x  于 12个月前  发布在  其他
关注(0)|答案(2)|浏览(109)

我从Syncfusion找到了一个DatGrid控件,并将其设置为:

<syncfusion:SfDataGrid x:Name="PasswdVw" Grid.Row="2"
    Grid.Column="2" Grid.RowSpan="2" ItemsSource="{Binding PassWrd}" SelectedRow="{Binding SelPassRws, Mode=TwoWay}"
    GridLinesVisibility="Both" SelectionMode ="Multiple"
    NavigationMode="Row" HeaderRowHeight="35"
    MaximumWidthRequest="1400" Margin="20,0,0,0"
    CellLongPress="PasswdVw_CellLongPress">

我想做的是只在某个列被点击时运行代码。所以在后面的代码中,我有这个:

private void PasswdVw_CellLongPress(object sender, DataGridCellLongPressEventArgs e)
{
    if(e.RowColumnIndex != 3)
    {
       return;
    }
    
    // continue with code here.
}

但是我总是在e.RowColumnIndex行得到错误消息,它说:

那么,如何使用我单击的相应列号或MappingName呢?

vsikbqxv

vsikbqxv1#

根据documentationDataGridCellLongPressEventArgs类的RowColumnIndex属性是同名的RowColumnIndex类,它包含两个整数字段:RowIndexColumnIndex,每个都是System.Int32(或int)类型。
因此,您不能将RowColumnIndex与整数进行比较,而只能将其成员与其他整数进行比较,例如:

private void PasswdVw_CellLongPress(object sender, DataGridCellLongPressEventArgs e)
{
    if(e.RowColumnIndex.ColumnIndex != 3)
    {
       return;
    }
    
    // continue with code here.
}
ghhaqwfi

ghhaqwfi2#

根据您提供的信息,您遇到的问题似乎与TypeConversion有关。您似乎试图将RowColumnIndex或DataGridColumn转换为整数值。
您可以选择从RowColumnIndex结构中提取RowIndex或ColumnIndex。或者,可以从DataGridCellLongPressEventArgs获取DataGridColumn。使用DataGridColumn,然后可以访问MappingName。请参考UG链接以获取更多信息。
UG链接-https://help.syncfusion.com/maui/datagrid/selection?cs-save-lang=1&cs-lang=csharp#celllongpress-event
代码片段:

private void dataGrid_CellLongPress(object sender, Syncfusion.Maui.DataGrid.DataGridCellLongPressEventArgs e)
{
    //To use column index and column index
    if(e.RowColumnIndex.ColumnIndex != 3) 
    {
        return;
    }
 
    //To use column mapping name
    if (e.Column.MappingName == "EmployeeID")
    {
        return;
    }
}

相关问题