Is it possible to immediately open a DataGridComboBoxColumn?

Is it possible when the Data Grid DataGridComboBoxColumn is displayed when the data grid is loading? By default, you need to click on a cell to open the combo box. I would like the user to see that the combo box is available without having to click on the cell. I would prefer the combo box to be immediately available, and the first click in the cell makes the combo box really omitted. Currently, you need to click on a cell and then click on the combo box to display the values.

Unwanted appearance

VS

Correct appearance

XAML:

<dg:DataGridComboBoxColumn x:Name="ctrlStatus" Header="Status" Width="Auto" SelectedValueBinding="{Binding Port}" SelectedValuePath="Status"> <dg:DataGridComboBoxColumn.CellStyle> <Style TargetType="dg:DataGridCell"> <EventSetter Event="Selector.SelectionChanged" Handler="SelectionChanged"/> </Style> </dg:DataGridComboBoxColumn.CellStyle> </dg:DataGridComboBoxColumn> 

Code for:

 List<string> _statusList; public List<string> StatusList { get { return _statusList; } set { _statusList = value; ctrlStatus.ItemsSource = _statusList; } } 

Thanks GAR8

COMPLETION OF THE DECISION: XAML

 <telerik:GridViewComboBoxColumn Header="Status"> <telerik:GridViewComboBoxColumn.CellTemplate> <DataTemplate> <telerik:RadComboBox ItemsSource="{Binding StatusList,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=UserControl}}" SelectedValue="{Binding Port}" SelectedValuePath="Status" SelectionChanged="SelectionChanged"/> </DataTemplate> </telerik:GridViewComboBoxColumn.CellTemplate> </telerik:GridViewComboBoxColumn> 

Code for:

 List<string> _statusList; public List<string> StatusList { get { return _statusList; } set { _statusList = value; } } 
+4
source share
2 answers

You can use a DataGridTemplateColumn and place the ComboBox as a cell edit template without specifying a template without editing. This will allow DataGrid to always use ComboBox.

Update
As mentioned in your comment, below is an example. Please note that the example is not optimal, and I would choose a different design, but I made it so that it integrates into your solution without big problems. I have not tested it. Make a comment if they are wrong.

 <DataGridTemplateColumn> <DataGridTemplateColumn.CellEditingTemplate > <DataTemplate> <ComboBox x:Name="ctrlStatus" SelectedValueBinding="{Binding Port}" SelectedValuePath="Status"> SelectionChanged="SelectionChanged" ItemsSource="{Binding StatusList,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window}}" /> </DataTemplate> </DataGridTemplateColumn.CellEditingTemplate> </DataGridTemplateColumn> 

To use the above code, the StatusList must execute a change notification. If your DataGrid is not in aWindow, but in another class, for example, in UserControl, replace the type name in the relative source.

+1
source

try it

 <DataGridTemplateColumn> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <ComboBox ItemsSource="{Binding Path=YourSource...}" Text="{Binding Path=YourSource...}"/> </DataTemplate> </DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellEditingTemplate > <DataTemplate> <ComboBox ItemsSource="{Binding Path=YourSource...}" Text="{Binding Path=YourSource...}"/> </DataTemplate> </DataGridTemplateColumn.CellEditingTemplate> </DataGridTemplateColumn> 

Basically you define a ComboBox in both cases, which are CellTemplate and CellEditingTemplate.

See the post that I wrote some time ago, in that I wrote a separate template for not editing (which you see initially) and editing (which you see when you click ie combobox) the state of the cell. Now you can copy the editing code into non-editing, as I did in XAML above, and your problem will be solved.

+2
source

All Articles