After multi-selecting rows of a DataGrid, how do I obtain values of specific columns from those selected rows using the behind-code?

Hello, I created a DataGrid in my MainPage.xaml file like this:

<syncfusion:SfDataGrid x:Name="GroupVw" ItemsSource="{Binding Grps}" Grid.Row="3" Grid.Column="0"

                               SelectionMode="Multiple" GridLinesVisibility="None" NavigationMode="Row" Margin="30,10,0,0"

                               HorizontalOptions="Center" HeaderRowHeight="0" Loaded="GroupVw_Loaded">

            <syncfusion:SfDataGrid.DefaultStyle>

                <syncfusion:DataGridStyle RowBackground="white" SelectionBackground="blue" SelectedRowTextColor="White"/>

            </syncfusion:SfDataGrid.DefaultStyle>

            <syncfusion:SfDataGrid.Columns>

                <syncfusion:DataGridTextColumn MappingName="GroupId" Width="0"/>

                <syncfusion:DataGridTextColumn MappingName="GroupName" Width="150" HeaderText="Group Name"/>

                <syncfusion:DataGridTextColumn MappingName="GroupTotal" Width="100" HeaderText="Total" CellTextAlignment="Center"/>

            </syncfusion:SfDataGrid.Columns>

        </syncfusion:SfDataGrid>


What I am looking to do is select 1 or more rows from the DataGrid, and each time a row is selected or deselected, an event or method gets executed that will scan through each selected row and use a specific column value of that row.

Is there anyone out there who can help?

I've tried sending this to Syncfusion tech support as a ticket but they keep answering my question in parts, and I usually have to wait at least a full day before I get an answer.

So please help.

Thanks.


1 Reply

NY Nirmalkumar Yuvaraj Syncfusion Team June 30, 2023 09:19 AM UTC

Hi Bob,


Based on the information provided, it seems that the problem you are facing is associated with converting the SelectedRows. We can obtain the specific column value by passing the desired column name, which serves as the mapping name for the converted value.


Code snippet :

private void GroupVw_SelectionChanged(object sender, Syncfusion.Maui.DataGrid.DataGridSelectionChangedEventArgs e)

    {

        var selRows = GroupVw.SelectedRows;

        int cntr = selRows.Count;

 

        if (cntr > 0)

            Ans.Text = "Selected: " + (selRows[0] as GroupInfo).GroupId.ToString();

        else

            Ans.Text = "Nothing Selected";

    }


Regards,

Nirmalkumar


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Loader.
Up arrow icon