【问题标题】:Syncfusion data grid how do i get the value of the cell click on by userSyncfusion数据网格如何获取用户单击的单元格的值
【发布时间】:2021-09-20 14:58:50
【问题描述】:

使用 Xamarin 的 Syncfusion 数据网格表单如何获取单元格值的内容。我已经包含了 Syncfusion 提供的网格事件。

https://help.syncfusion.com/xamarin/datagrid/grid-events

<sfgrid:SfDataGrid x:Name="sfGrid" 
        AllowSorting="True"
        ColumnSizer="Star"
        AllowDraggingRow="True"
        SelectedIndex="2"
        AllowResizingColumn="True"
        SelectionMode="Single"
        AllowEditing="True"
        NavigationMode="Cell"
        AllowKeyboardNavigation="True"
        AutoGenerateColumns="False"
        ItemsSource="{Binding Students}">
    <sfgrid:SfDataGrid.Columns x:TypeArguments="syncfusion:Columns">

        <sfgrid:GridTextColumn HeaderText="First Name" 
         MappingName="FirstName" />
        <sfgrid:GridTextColumn HeaderText="Last Name" 
                    MappingName="LastName" />
        <sfgrid:GridTextColumn HeaderText="TB" 
                    MappingName="TB" />
        <sfgrid:GridTextColumn HeaderText="PU" 
                    MappingName="PU" />
    </sfgrid:SfDataGrid.Columns>
</sfgrid:SfDataGrid>

例如,用户点击 TB 的单元格,在第 2 行该值为 108.7,我想获得该值。

 public AcitivtyListPage()
 {
    InitializeComponent();

    this.BindingContext = new StudentsViewModel();        
    sfGrid.CurrentCellActivated += SfGrid_CurrentCellActivated;
    }

  } 

我尝试查看 CurrentCellActivated,但它似乎没有选定的单元格值对象。

 private void SfGrid_CurrentCellActivated(object sender, Syncfusion.SfDataGrid.XForms.CurrentCellActivatedEventArgs e)
 {
        var item = sfGrid.GetSelectedCells();
 }

我也尝试了这个示例,但它不适用于较新版本的控件,某些方法不再存在。

https://www.syncfusion.com/kb/7436/how-to-get-the-cell-value-of-specific-row-and-column

当红色框围绕网格单元格时,此图形应该解释它,我想要的值包含在该单元格中,请参见下图。

【问题讨论】:

  • CurrentCellActivatedEventArgs 有一个 CurrentRowColumnIndex 属性
  • 是的,但我不想要那行数据我想要我在@Jason 上录制的单元格我只想更新它的值
  • CurrentRowColumn索引 - 这是特定单元格的索引,而不是整行
  • 是的,但它返回给我的只是一个数字,而不是单元格ceotents数字我如何得到@Jason

标签: c# xamarin.forms syncfusion


【解决方案1】:

您可以在 CurrentCellActivated 事件上使用 SfDataGrid 的 GetCellValue() 方法获取当前单元格值。请参考以下代码sn-p。

代码sn-p:

<syncfusion:SfDataGrid x:Name="dataGrid" SelectionMode="Single" NavigationMode="Cell" CurrentCellActivated="dataGrid_CurrentCellActivated" AutoGenerateColumns="False" ItemsSource="{Binding mycollect}" ColumnSizer="Star"> 
  
                <syncfusion:SfDataGrid.Columns> 
                    
                        <syncfusion:GridTextColumn LoadUIView="True" MappingName="No_1"></syncfusion:GridTextColumn> 
                    <syncfusion:GridTextColumn LoadUIView="True" MappingName="No_1"></syncfusion:GridTextColumn> 
                    <syncfusion:GridTextColumn LoadUIView="True" MappingName="No_1"></syncfusion:GridTextColumn> 
                </syncfusion:SfDataGrid.Columns> 
  
            </syncfusion:SfDataGrid>

....
 private void dataGrid_CurrentCellActivated(object sender, CurrentCellActivatedEventArgs e) 
        { 
            
            var dataRow = dataGrid.GetRowGenerator().Items.FirstOrDefault(x => x.RowIndex == e.CurrentRowColumnIndex.RowIndex); 
           var CellValue = dataGrid.GetCellValue(dataRow.RowData, dataGrid.Columns[e.CurrentRowColumnIndex.ColumnIndex].MappingName); 
        } 

【讨论】:

    猜你喜欢
    • 2019-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-17
    • 2022-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多