Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ComboBox - Setting SelectedItem to an item within the ComboBox does not select the item #10023

Open
johnt-star opened this issue Sep 22, 2024 · 0 comments
Labels
area-ComboBox team-Controls Issue for the Controls team

Comments

@johnt-star
Copy link

Describe the bug

If you try to use the ComboBox SelectedItem to select an entry within the ComboBox, the entry is not being selected.

NOTE that this use to work, but I am not sure which Visual Studio and/or WinAppSDK update changed this functionality.

I use to be able to load a ComboBox with strings, then select an item by setting SelectedItem = "myString";

Steps to reproduce the bug

  1. Load a ComboBox with a series of strings.
  2. Use the ComboBox's SelectedItem property to select a string in the middle of the list.

Issue: instead of displaying the string the ComboBox's display remains blank.

Expected behavior

You should be able to display an item within a ComboBox by setting its SelectedItem property in the same manner as setting its SelectedIndex property.

Screenshots

The code loads a ComboBox and tries to select an item by setting SelectedItem property.

However, the item is not selected and ComboBox is blank.

Blank ComboBox at startup:
image

ComboBox is properly populated:
image

Breakpoint shows SelectedItem property is null after selection:
image

NuGet package version

Windows App SDK 1.6.0: 1.6.240829007

Packaging type

Packaged (MSIX)

Windows version

No response

IDE

Visual Studio 2022

Additional context

MainWindow.xaml

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
    <ComboBox Name="ComboBoxMain"></ComboBox>
</StackPanel>

MainWindow.xaml.cs
public sealed partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();

        AddComboBoxMembers();
    }


    private void AddComboBoxMembers()
    {
        int iIdx;

        string sItem;

        ComboBoxItem comboBoxItem;

        for (iIdx = 0; iIdx < 10; ++iIdx)
        {
            sItem = "Item" + iIdx.ToString();

            comboBoxItem = new ComboBoxItem
            {
                Content = sItem,
            };

            ComboBoxMain.Items.Add(comboBoxItem);
        }

        sItem = "Item5";

        ComboBoxMain.SelectedItem = sItem;
    }

}
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Sep 22, 2024
@codendone codendone removed the needs-triage Issue needs to be triaged by the area owners label Sep 26, 2024
@codendone codendone transferred this issue from microsoft/WindowsAppSDK Sep 26, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Sep 26, 2024
@codendone codendone added area-ComboBox team-Controls Issue for the Controls team and removed needs-triage Issue needs to be triaged by the area owners labels Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-ComboBox team-Controls Issue for the Controls team
Projects
None yet
Development

No branches or pull requests

2 participants