Hi everyone! I recreate the post, because perhaps the problem was not understood before.
I created this code to ensure that when the user clicks twice on the selected row, the card modification window opens automatically, and to do this I need to have the value of the ID column, up to two days it used to work, today it doesn't work anymore, unfortunately I have no way to view the previous code, since I saved the changes on github only once I "damaged" the code (I'm stupid I know).
Having said that, when I enter debug mode on "InvoiceList.SelectedItem" all the values of the respective cells are perfectly visible, in my opinion the error is in ListData, which however I cannot correct
This is the code on Pastebin
Having said that I would need your help to correct the error, or if you know if there is another way to get the data from that specific column,
Hi Daniele,
We have checked the provided link, and it did not load from our end. However, your requirement to get the data from
that specific column of the selected row in SfDataGrid can be achieved by using View.GetPropertyAccessProvider.GetValue
method in SfDatGrid. Refer to the below code snippet,
|
private void OnGetCellvalueClicked(object sender, RoutedEventArgs e) { var record = sfDataGrid.SelectedItem; //Here get the cell value by passing the specific column (Ex: Country) mapping name var cellValue = sfDataGrid.View.GetPropertyAccessProvider().GetValue(record, "Country");
Console.WriteLine("Single Selection Case Getting Selected Row value :" + cellValue.ToString());
//Multiple selection foreach(var item in sfDataGrid.SelectedItems) { // loop through get the all selected row values of Country column var cellValue1 = sfDataGrid.View.GetPropertyAccessProvider().GetValue(item, "Country"); Console.WriteLine("Multiple Selection Case Getting Selected Rows value :" + cellValue1.ToString()); } } |
For more information related to getting cell value, refer to the below user guide documentation link,
UG Link: https://help.syncfusion.com/wpf/datagrid/selection#currentcellactivating-event
https://help.syncfusion.com/wpf/datagrid/selection
KB Link: https://www.syncfusion.com/kb/6384/how-to-read-cell-values-from-selecteditems
https://www.syncfusion.com/kb/2446/how-to-get-the-current-cell-value-when-you-click-the-cell
Find the sample demo in the attachment.
Regards,
Vijayarasan S
If this post is helpful, please consider Accepting it as the solution so that
other members can locate it more quickly.
Thank you very much for helping!
Last question, I have a "SUPPLIER_ID" column, when I start the window, I need to get the data from the "SUPPLIER_ID" column for each row, what can I use? I noticed there is no "SfDataGrid.Items" or similar
Hi Daniele,
Your requirement can be achieved by using the SfDataGrid.View.Record. Please find the below code snippet,
Code snippet:
|
private void SfDataGrid_Loaded(object sender, RoutedEventArgs e) { foreach(var record in sfDataGrid.View.Records) { var requiredData = (record.Data as OrderInfo).CustomerName; // Here, you can get the specific column record for each of the rows. } } |
Regards,
Sreemon Premkumar M.
HI!
Thanks for the reply, in the line of code there is "OrderInfo" what does it refer to?
"CustomerName" is the name of the column I guess, however Visual Studio doesn't suggest me any column present in the SfDataGrid, but "OrderInfo" I can't figure out what it's for and how to connect it.
private void InvoiceList_Loaded(object sender, RoutedEventArgs e) { foreach (var recordSupplier in InvoiceList.View.Records) { var requiredData = (recordSupplier.Data as OrderInfo).ID_FORNITORE; MessageBox.Show("Test: " + requiredData); } } |
<syncfusion:SfDataGrid x:Name="InvoiceList" Grid.Row="1" AutoGenerateColumns="False" FontSize="20" ColumnSizer="Auto" Margin="10,5,10,0" AllowEditing="False" SelectionMode="Single" SelectionUnit="Row" NavigationMode="Row" MouseDoubleClick="InvoiceList_MouseDoubleClick" Loaded="InvoiceList_Loaded"> <syncfusion:SfDataGrid.Columns> <syncfusion:GridTextColumn MappingName="ID" HeaderText="ID"/> <syncfusion:GridTextColumn MappingName="SUPPLIER_ID" HeaderText="SUPPLIER"/> <syncfusion:GridTextColumn MappingName="SUPPLIER_NAME" HeaderText="SUPPLIER"/> <syncfusion:GridTextColumn MappingName="HOLDER" HeaderText="HOLDER"/> <syncfusion:GridTextColumn MappingName="CUSTOMER_CODE" HeaderText="CUSTOMER CODE"/> <syncfusion:GridTextColumn MappingName="PDR" HeaderText="PDR"/> <syncfusion:GridTextColumn MappingName="ADDRESS" HeaderText="ADDRESS"/> <syncfusion:GridCheckBoxColumn MappingName="ACTIVE" HeaderText="ACTIVE"/> <syncfusion:GridDateTimeColumn MappingName="ISSUE_DATE" HeaderText="ISSUE DATE"/> <syncfusion:GridTextColumn MappingName="INVOICE_NUMBER" HeaderText="INVOICE NUMBER"/> <syncfusion:GridCurrencyColumn MappingName="AMOUNT_TO_PAY" HeaderText="AMOUNT TO PAY" CurrencyDecimalDigits="2" CurrencyDecimalSeparator="." CurrencyGroupSeparator="," CurrencyGroupSizes="3"/> <syncfusion:GridDateTimeColumn MappingName="PERIOD_START" HeaderText="PERIOD START"/> <syncfusion:GridDateTimeColumn MappingName="PERIOD_END" HeaderText="PERIOD END"/> <syncfusion:GridDateTimeColumn MappingName="DUE_DATE" HeaderText="DUE DATE"/> <syncfusion:GridTextColumn MappingName="PAYMENT_STATUS" HeaderText="PAYMENT STATUS"/> </syncfusion:SfDataGrid.Columns> </syncfusion:SfDataGrid> |
Daniele,
Solution 1:
OrderInfo is a type underlying class that contains properties of collection bound
with DataGrid. Example: ObservableCollection<OrderInfo> is
declaring an ObservableCollection that will hold objects of type OrderInfo.
This means that you can add, remove, and manipulate OrderInfo objects
within the collection, and any changes made to the collection will
automatically notify any data-bound UI elements to update themselves, which can
be helpful in scenarios where you need to reflect changes in a collection in a
user interface, such as a list of orders.
A collection of OrderInfo type objects (List<OrderInfo> or
ObservableCollection<OrderInfo>) will be assigned as ItemsSource for the
SfDataGrid, you should cast the record to the underlying data object
or underline business object or underline model as previously
mentioned update like shown below,
Code Snippet related to Underlying property bound with SfDataGrid:
|
private ObservableCollection<OrderInfo> _orders; public ObservableCollection<OrderInfo> Orders { get { return _orders; } set { _orders = value; } }
<syncfusion:SfDataGrid x:Name="sfDataGrid" ItemsSource="{Binding Orders}" AllowEditing="True" SelectionMode="Extended" AutoGenerateColumns="False"> |
C# code snippet related to getting cell value using the underlying property:
|
//Here get the record value by looping through records collection foreach (var record in sfDataGrid.View.Records) { // Here, you can get the specific column record for each of the rows. //Based on using the column mapping name, you can get the record value var requiredData = (record.Data as OrderInfo).Country;
} |
Solution 2:
You can get the cell value by passing the RecordEntry.Data
value to View.GetPropertyAccessProvider.GetValue method in SfDatGrid. Refer to
the below code snippet,
|
//Here get the record value by looping through records collection foreach (var recordEntry in sfDataGrid.View.Records) { // Get the record value var record = recordEntry.Data; // Get the country column value using GetPropertyAccessProvider var cellValue1 = sfDataGrid.View.GetPropertyAccessProvider().GetValue(record, "Country"); } |
Find the modified sample demo in the attachment.
If this post is helpful, please consider Accepting it as the solution so that
other members can locate it more quickly.