SfDataGrid new entry and GridComboboxColumn

Dear Sir or Madam,

I have 2 problems.

First of all, I get a NullReferenceExcpetion on adding a new row in the Grid. I changed the behavior of the enter key down handling, so it reacts like a tab. I don't know where or why the Exception is thrown in the override void ProcessOnTapped function.

​Second, I need a Combobox where I can display diferent values in the DropDown Box and the displaymember in the selected cell of the Grid. The property I want to show is not at the ItemSource on the Grid, but on the ItemSource of the Combobox.

I managed to edit the DropDown Box in the ComboBox, but can´t show the the selected value in the grid cell (only one property)

I have attached a sample Project. 

Thanks for your help

And with kind regards.


Attachment: SyncfusionGrid_f5690288.7z

3 Replies 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team April 7, 2021 04:51 PM UTC

Hi Manuel Steeb,

Thank you for your patience.

Please find answer for your queries below
 
Queries 
Solutions 

I get a NullReferenceExcpetion on adding a new row in the Grid. I changed the behavior of the enter key down handling, so it reacts like a tab. I don't know where or why the Exception is thrown in the override void ProcessOnTapped function.

 

Based on provided information we have checked the provided sample. In your application AddNewRow initiating event process AddNewRow commit and SelectedItems clear in event. These are different thread running at a time in your application. So, your requirement can be achieved by Calling the SfDataGrid.Dispatcher.BeginInvoke in AddNewRowInitiating in SfDataGrid. Please refer the below code snippet,

 
private void SfGridBeihilfeAntragBeleg_OnAddNewRowInitiating(object sender, AddNewRowInitiatingEventArgs e) 
{ 
            if (e.OriginalSender is SfDataGrid dataGrid) 
            { 
                dataGrid.Dispatcher.BeginInvoke(new Action(() => 
                { 
                    if (dataGrid.View.IsAddingNew) 
                    { 
 
                        if (dataGrid.SelectionController.CurrentCellManager.CurrentCell.IsEditing) 
                            dataGrid.SelectionController.CurrentCellManager.EndEdit(true); 
 
                        var rowColumnIndex = dataGrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex; 
 
                        //Process the commit operation in AddNewRow. 
                        var addNewRowController = dataGrid.GetAddNewRowController(); 
                        addNewRowController.CommitAddNew(); 
 
                        //Gets the row index of AddNewRow  
                        rowColumnIndex.RowIndex = addNewRowController.GetAddNewRowIndex(); 
                        dataGrid.SelectedItems.Clear(); 
 
                        //If the AddNewRowPosition is Top need to move the current cell to next row  
                        if (dataGrid.AddNewRowPosition == AddNewRowPosition.Top) 
                            rowColumnIndex.RowIndex = rowColumnIndex.RowIndex + 1; 
 
                        //Which retains the current cell border in the row after canceling AddNewRow as you press ESC key operation. 
                        //dataGrid.MoveCurrentCell(rowColumnIndex); 
                    } 
                })); 
            } 
} 



 
 
I need a Combobox where I can display diferent values in the DropDown Box and the displaymember in the selected cell of the Grid. The property I want to show is not at the ItemSource on the Grid, but on the ItemSource of the Combobox. 
 
 
We are little unclear with your reported scenario. Based on provided information we suspect that your requirement is only display the Name property in GridComboBoxColumn. Only set the DisplayMember property as Name in GridComboBoxColumn.  No need to define the Item Template in GridComboBoxColumn. Please refer the below code snippet,

 
  <sf:GridComboBoxColumn 
                        AllowEditing="True" 
                        DisplayMemberPath="Name" 
                        HeaderText="Land Combo" 
                        IsReadOnly="False" 
                        ItemsSource="{Binding Countries}" 
                        MappingName="CountryId" 
                        CellStyle="{StaticResource TextBlockStyle}" 
                        SelectedValuePath="Id"> 
                    </sf:GridComboBoxColumn> 
 
Screenshot for your reference,



If your requirement is display the combobox itemsource values in SfDataGrid. You can achieve this by without set the DisplayMemeber property in GridComboBoxColumn in SfDataGrid. Please refer the below code snippet,

 
<sf:GridComboBoxColumn 
                        AllowEditing="True"                        
                        HeaderText="Land Combo" 
                        IsReadOnly="False" 
                        ItemsSource="{Binding Countries}" 
                        MappingName="CountryId" 
                        CellStyle="{StaticResource TextBlockStyle}" 
                        SelectedValuePath="Id"> 
                        <sf:GridComboBoxColumn.ItemTemplate> 
                            <DataTemplate> 
                                <TextBlock> 
                                    <Run Text="{Binding Path=Name}" /> 
                                    <Run Text="{Binding Path=IsoAplha2}" /> 
                                    <Run Text="{Binding Path=CultureInfo}" /> 
                                </TextBlock> 
                            </DataTemplate> 
                        </sf:GridComboBoxColumn.ItemTemplate> 
</sf:GridComboBoxColumn> 
 
 
Screenshot for your reference, 
 
 
If we misunderstood your requirement, please provide more information regarding the requirement. This would help us to proceed further. 
 
 
Please let us know if you have any concerns in this. 

Regards,
Vijayarasan S
 


Marked as answer

MS Manuel Steeb April 14, 2021 12:09 PM UTC

Hi,

i want 2 different styles in the Combobox, in the Dropdown Element I want to show three Properties Name, IsoAplha2 and CultureInfo, the selected Value should only displayed as the Country Name so the Property Name in the Grid Cell.

Thx for your Help


VS Vijayarasan Sivanandham Syncfusion Team April 15, 2021 06:00 PM UTC

Hi Manuel Steeb,

Thanks for the update.
 
We are little unclear with your scenario. Can you please provide the more information related to your query?

Can you please share us below things?
       
        1.
Can you please confirm when click into Combobox dropdown shows the three-column values and after selecting an item in Combobox only displays the country column value in SfDataGrid
        2.
Provide more details about your scenario with illustrations?  
        3. Provide more details about your scenario with image illustrations?   
 
It will be helpful for us to check on it and provide you the solution at the earliest.

Regards,
Vijayarasan S
 


Loader.
Up arrow icon