Regarding the strange behavior observed when I single-click on a cell in the grid ~ Split from 197195

Hi I am getting this strange behavior whenever I click (single click) on the cell. It changes my button to this which it appears to be getting from a field of my Staff view model called Shifts. If I search for "Shifts:" in my code it returns no result. 

 


I am wondering whether the following code is triggering this:

private void OnClick(object sender, RoutedEventArgs e)
{    
    var visualContainer = MainDataGrid.GetVisualContainer();
    if (visualContainer != null && MainDataGrid.SelectionController != null && MainDataGrid.SelectionController.CurrentCellManager != null)
    {
        var rowColumnIndex = visualContainer.PointToCellRowColumnIndex(lastMousePosition);
         if (rowColumnIndex != null)
        {            
            MainDataGrid.MoveCurrentCell(rowColumnIndex);
        }
        MainDataGrid.SelectionController.CurrentCellManager.BeginEdit();
    }
}

8 Replies

SB Sweatha Bharathi Syncfusion Team August 8, 2025 10:15 AM UTC

Hi Alfred Smith,

We have reviewed your query . When the button is clicked, we can display the SfComboBox . In the click event handler, we can call the BeginEdit method to activate edit mode, which will display the SfComboBox. The content shown in the Button is based on the count of selectedItems of SfComboBox, along with the prefix "View".
We are not able to replicate your scenario. The selected items count is properly shown in the Button as expected.
We have provided a video for your reference. Kindly review the video. If you are still facing issues, please modify the provided sample to replicate your scenario. 
This will help us better understand your requirement and provide an effective solution.


Regards,
Sweatha B

Attachment: Video_e3ffc6c3.zip


AS Alfred Smith replied to Sweatha Bharathi August 10, 2025 04:19 PM UTC

Hi I did some digging and found what the cause is for this strange behaviour. For some reason my ComboBox is showing the whole Data Context object in the header/button area of the Combo Box when going into edit mode, instead of a header. As only the first item in the collection can fit, that is the only property being shown. That property just happens to be Shifts.

This is the collection its outputting (only the first property is visible on screen):

Shifts: (null)
FullName: Steve T Tink
MiddleName: T
Gender: Male
DateOfBirth: (null)
HighlightColor: (null)
FirstName: Steve
LastName: Tink
Nickname: Stevo

I want it so that it display something like "Available Clients" instead.


Screenshot of what it's doing currently: 



SB Sweatha Bharathi Syncfusion Team August 11, 2025 09:44 AM UTC

Alfred Smith,

We have reviewed your query. In SfComboBox, the text is displayed based on the DisplayMemberPath. This property specifies which field of the objects in the ComboBox's ItemsSource should be shown. Therefore, whatever is set in DisplayMemberPath will be displayed in the SfComboBox.

If the goal is to show client names in the SfComboBox, ensure that the underlying data contains the client name field and assign that field to DisplayMemberPath.

In the provided sample, the underlying property FullName is set as the DisplayMemberPath. This property holds the name of the available client, which is displayed in the SfComboBox.

Based on the retrieved SelectedItems from the SfComboBox, you can assigned the retrieved value to the button content.

Code snippet to assign an DisplayMemberPath:

 <dataGrid:GridTemplateColumn MappingName="ClientName"
                              HeaderText="ClientDetails">
     <dataGrid:GridTemplateColumn.CellTemplate>
         <DataTemplate>
             <StackPanel>
                 <Button Content="{Binding ClientName, Converter={StaticResource ClientNameConverter}}"
                         HorizontalAlignment="Center"
                         VerticalAlignment="Center"
                         Click="OnClick"
                         />
             </StackPanel>
         </DataTemplate>
     </dataGrid:GridTemplateColumn.CellTemplate>
     <dataGrid:GridTemplateColumn.EditTemplate>
         <DataTemplate>
             <editors:SfComboBox x:Name="sfComboBox"
                                 DisplayMemberPath="FullName"
                                 DataContext="{Binding AllClients,Source={StaticResource ViewModel}}"  
                                 Loaded="OnLoaded"
                                 SelectionMode="Multiple"
                                 Width="150"
                                 SelectionChanged="OnSelectionChanged" />
         </DataTemplate>
     </dataGrid:GridTemplateColumn.EditTemplate>
 </dataGrid:GridTemplateColumn>

Image Reference:



AS Alfred Smith replied to Sweatha Bharathi August 11, 2025 04:58 PM UTC

Hi I have the following Xaml code which sets the DisplayMemberPath, however the result is this:


Image_3801_1754927139731


My Xaml Code:

<dataGrid:GridTemplateColumn.EditTemplate>
    <DataTemplate>
        <editors:SfComboBox
            x:Name="sfComboBox"
            Width="150"
            DataContext="{Binding ClientList, Source={StaticResource PageViewModel}}"
            DisplayMemberPath="FullName"
            Loaded="OnLoaded"
            SelectionChanged="OnSelectionChanged"
            SelectionMode="Multiple" />
    </DataTemplate>
</dataGrid:GridTemplateColumn.EditTemplate>


If I change DisplayMemberPath to some other property such as "FirstName" the result is the same.



AS Alfred Smith August 12, 2025 09:13 AM UTC

I have included an image of what I am trying to achieve. The image on the left is how it is currently and the one on the right is what I am trying to create.


comboBox example.png


This is my OnLoaded function which is called when the user opens up the combobox by click on the button and going into edit mode.


private void OnLoaded(object sender, RoutedEventArgs e)
{
    firstTimeLoaded = true;   
    var comboBox = sender as SfComboBox;
    if (comboBox == null)
    {
        return;
    }        
     var dataRow = FindParent<DataGridRowControl>(comboBox);
    if (dataRow == null)
    {
        return;
    }


    var record = dataRow.DataContext;
    if (record == null || record is not StaffViewModel staff)
    {
        return;
    }   
    var dataContextItems = comboBox.DataContext as IEnumerable<ClientViewModel>;
    if (dataContextItems == null)
    {
        return;
    }               
    bool itemFound = false;
    foreach (ClientViewModel item in dataContextItems)
    {
        comboBox.Items.Add(item);
        if (staff.Clients != null)
        {
            if (staff.Clients.Count > 0)
            {
                foreach (ClientViewModel clientVM in staff.Clients)
                {
                    if (clientVM.Id == item.Id)
                    {
                        itemFound = true;
                    }
                }
                if (itemFound)
                {
                    if (comboBox.SelectedItems != null)
                    {                        
                        comboBox.SelectedItems.Add(item);
                    }
                    itemFound = false;
                }               
            }
        }
    }
}



SB Sweatha Bharathi Syncfusion Team August 12, 2025 11:54 AM UTC

Hi Alfred Smithi,

We have reviewed your query along with the provided code snippet and image reference. Based on our analysis, we suspect that you have customized the SfComboBox. By default, the SfComboBox appears as shown below, but in your provided image, it displays labels like "Shifts:" and expects "AvailableClients".

Image Reference:



Could you please confirm whether you have customized the SfComboBox beyond what we provided in our sample? If yes, kindly share the customization details.

If possible, please modify the sample we provided to reflect your scenario. This will help us proceed further. Without being able to replicate the issue on our side, we are unable to provide a solution. So kindly update our sample to reproduce your scenario.

Regards,
Sweatha B


AS Alfred Smith replied to Sweatha Bharathi August 12, 2025 03:29 PM UTC

Hi as far as I can tell my code is very similar to yours. The reason it shows "Shifts: Null" is that the DisplayMemberPath doesn't appear to be working and instead its trying to display the whole object. The shifts property just happens to be the first in order and therefore gets shown on the combo box, the rest are hidden due to lack of room.


This is the full object its trying to output:


Shifts: (null)
FullName: Steve T Tink
MiddleName: T
Gender: Male
DateOfBirth: (null)
HighlightColor: (null)
FirstName: Steve
LastName: Tink
Nickname: Stevo
Phone: (null)
EmailAddress: (null)
Address: (null)


I have noticed that if a staff member doesn't have any clients assigned instead of showing "Shifts: Null", its just blank. If i comment out this line of code in the OnLoaded function it no longer shows "Shifts:Null" and is instead just blank. So for whatever reason DisplayMemberPath=FullName isn't working. 

comboBox.SelectedItems.Add(item);




SB Sweatha Bharathi Syncfusion Team August 13, 2025 10:16 AM UTC

Alfred Smith ,

We have created a support ticket under your account in our ticketing system. To proceed further with your requirement, we kindly request you to follow that for further updates. 

Loader.
Up arrow icon