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();
}
}
Attachment: Video_e3ffc6c3.zip
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:
<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> |
Hi I have the following Xaml code which sets the DisplayMemberPath, however the result is this:
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.
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.
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;
}
}
}
}
}
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);
- 8 Replies
- 2 Participants
-
AS Alfred Smith
- Aug 8, 2025 05:51 AM UTC
- Aug 13, 2025 10:16 AM UTC