WPF : GridViewComboBoxColumn not showing dropdown until click

1 Answer 58 Views
ComboBox General Discussions GridView
Olabamiji
Top achievements
Rank 1
Olabamiji asked on 04 Nov 2022, 02:20 PM

I'm trying to make my gridview box column show the dropdown tick without having to click

 


<telerik:GridViewComboBoxColumn Header="Active" DataMemberBinding="{Binding EnableCase}" UniqueName="Active" ItemsSource="{Binding Activeops}" DisplayMemberPath="Describe" SelectedValueMemberPath="ID" />

 

The Dropdown only shows up when i click on the header

 

 

1 Answer, 1 is accepted

Sort by
-1
Stenly
Telerik team
answered on 08 Nov 2022, 05:52 PM

Hello Olabamiji,

By default, when a cell from the GridViewComboBoxColumn is not in edit mode, the selected item will be hosted in a TextBlock element. Once a cell goes into edit mode, a RadComboBox element will be displayed, in order to select a new value. 

To achieve the desired functionality, instead of using the GridViewComboBoxColumn, a new GridViewDataColumn could be created. Then, define a custom DataTemplate that will contain a RadComboBox element and set it to the CellTemplate property of the new column.

A sample implementation of this suggestion would look as follows:

<telerik:GridViewDataColumn>
	<telerik:GridViewDataColumn.CellTemplate>
		<DataTemplate>
			<telerik:RadComboBox  ItemsSource="{Binding MyCollection}"/>
		</DataTemplate>
	</telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>

More information about the CellTemplate property could be found at the following link:

WPF DataGrid | CellTemplate and CellEditTemplate | Telerik UI for WPF

With this being said, I hope the provided information will be of help to you.

Regards,
Stenly
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Paul
Top achievements
Rank 2
Iron
Iron
Iron
commented on 24 Nov 2023, 04:01 PM

The above does not work. It does show a combobox but it does not use the itemsource.
It is highly frustrating to have to even be trying to do this. Who in your organisation thought that an invisible combobox was a good idea? Did nobody in testing suggest that a list to select from that you cannot see it a bad UI?
Stenly
Telerik team
commented on 27 Nov 2023, 12:32 PM

Hello Paul,

Showing a RadComboBox only in edit mode when using the GridViewComboBoxColumn was a design decision when it was initially developed. When the cells in this column are not in edit mode, a TextBlock will be used to display the selected value.

The suggestion for using a column different than the GridViewComboBoxColumn with a RadComboBox in its CellTemplate property is one way to achieve this requirement. However, the elements in the DataTemplate for this property will not have the same DataContext object as the RadGridView control. More specifically, it will be the object from the ObservableCollection set to the ItemsSource property of RadGridView. This could be the reason why no items are displayed on your end. If this is the case, you could use the RelativeSource property of the Binding instance to bind to the collection from the DataContext object from the RadGridView.

The following code snippet shows the above suggestion's implementation:

<telerik:GridViewColumn>
	<telerik:GridViewColumn.CellTemplate>
		<DataTemplate>
			<telerik:RadComboBox  ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=telerik:RadGridView}, Path=DataContext.MyCollection}"/>
		</DataTemplate>
	</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewDataColumn>

Alternatively, you could create a custom column and override the CreateCellElement method. In it, you can return a RadComboBox instance, which will be used when the cells of this column are not in edit mode. The following article shows how to create a button column and the approach can be customized to use the RadComboBox control instead:

WPF DataGrid - Add a Button Column - Telerik UI for WPF

I hope the provided information will be of help to you.

Tags
ComboBox General Discussions GridView
Asked by
Olabamiji
Top achievements
Rank 1
Answers by
Stenly
Telerik team
Share this question
or