How to use a ComboBox as a dropdown menu

mauede

Well-known member
Joined
Sep 1, 2021
Messages
103
Location
Northwood - UK
Programming Experience
Beginner
I have to show a list of strings (Trial names) that are fetched from a PostgreSQL database. The number of strings is only known at runtime.
I have implemented that through a ComboBox as follows:

C#:
      <ComboBox x:Name="TrialDB" Grid.Row="1" Grid.Column="1"  MinWidth="100"  Grid.ColumnSpan="21"
                  ItemsSource="{Binding Path=MainWindow, Mode=OneWay}" 
                  Background="Ivory" Margin="110,0,112,38" SelectionChanged="TrailDB_SelectionChanged" Selected="TrailDB_Selected" >
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock  x:Name="SQLDB" Text="{Binding trials}" Grid.Column="0" Padding="5,2" HorizontalAlignment="Center" FontFamily="Arial Black" FontSize="20" Width="250" />
                    </Grid>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>


I also have to allow the user to select a string, from that ComboBox, that identifies a Trial name and upon this selection, I have to fetch another set of strings (Structure names) from the same PostgreSQL database and populate a ListBox.
My problem is to find two appropriate ComboBox events. One event to display the list of Trial names and another event to honor the user selection of a Trial name.
I thought to use the "SelectionChanged" event to deal with the selection of a Trial (a ComboBox item).
I need another event to awaken my code unit that fetches the Trial names from the PostgreSQL database and displays them as ComboBox items.
Although the Visual Studio list of ComboBox prefixed events contains "Selected", the compiler complains stating that "Selected" is not found for ComboBox.
Which event should I use?
If none of the ready-to-use events is appropriate for my goal, how can I create and handle my own ComboBox event?
Thank you so much for your attention.
 

Latest posts

Back
Top Bottom