0

I found a DatGrid control from Syncfusion and set it up like this:

<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">

and what I want to do is only run code if a certain column is clicked. So In the behind-code I have this:

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

But I always get the error message at the e.RowColumnIndex line that says:

enter image description here

So how do I use the corresponding column number or MappingName that I clicked on?

Julian
  • 5,290
  • 1
  • 17
  • 40
BobG
  • 9
  • 1
  • https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.DataGridCellLongPressEventArgs.html#Syncfusion_Maui_DataGrid_DataGridCellLongPressEventArgs_RowColumnIndex – Jason Aug 26 '23 at 17:25
  • You've asked [another question](https://stackoverflow.com/questions/76986996/how-do-i-update-a-specific-cell-in-a-datagrid-control-of-a-net-maui-application) about the SfDataGrid, which seems to be a follow-up. Did you fix this issue? – Julian Aug 27 '23 at 13:28
  • Please don't post errors (or code) as images. – Julian Aug 27 '23 at 13:30

2 Answers2

0

As per the documentation, the RowColumnIndex property of the DataGridCellLongPressEventArgs class is of the equally named RowColumnIndex class, which holds two integer fields: RowIndex and ColumnIndex, each of type System.Int32 (or int).

Therefore, you cannot compare the RowColumnIndex with an integer, instead you can only compare its members with other integers, e.g.:

private void PasswdVw_CellLongPress(object sender, DataGridCellLongPressEventArgs e)
{
    if(e.RowColumnIndex.ColumnIndex != 3)
    {
       return;
    }
    
    // continue with code here.
}
Julian
  • 5,290
  • 1
  • 17
  • 40
0

Based on the information you have provided, it seems that the problem you're encountering is connected to TypeConversion. It appears that you're attempting to convert either a RowColumnIndex or a DataGridColumn into an integer value.

You have an option to extract a RowIndex or ColumnIndex from the RowColumnIndex struct. Alternatively, you can obtain the DataGridColumn from the DataGridCellLongPressEventArgs. Using the DataGridColumn, you can then access the MappingName. Please refer to the UG link for more information.

UG link - https://help.syncfusion.com/maui/datagrid/selection?cs-save-lang=1&cs-lang=csharp#celllongpress-event

Code snippet:

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;
    }
}