Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a WPF ComboBox that binds to a set of data. I do not have permissions to modify the control directly, nor can I change the data.

I'm returned 1 item in my ComboBox, but there are actually 2 rows; the blank row and my expected value. Both appear to have an index value of 0. I don't want to see this blank row, just my expected data in the ComboBox auto-selected. I have looked through everyone's related posts in here, but none of the solutions have worked for my case. I have been programming for a long time, but still fairly new to WPF. Thanks for the help.

XAML

<MyComboBox Name="myTemplate5" MyLookup="Lookup" MyFilter="att_idn=-37" MyData="Detail" MyName="comp_tmpl_idn_srt" ModCde="31" MyEmptyValue="0" ToolTip="Have a nice day" Margin="0,2.5,30,2.5" MinWidth="120" Grid.Column="1"  SelectionChanged="myTemplate5_SelectionChanged" />

C#

private void myTemplate1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    MyComboBox work = sender as MyComboBox;
    if (work != null && work.HasSelectionChanged(e))
    {
        int compTmplId = int.Parse(work.SelectedValue.ToString());
        if (!_wpfIsDumb && !ChangeComponent(compTmplId))
        {
            _wpfIsDumb = true;
            work.SelectedItem = e.RemovedItems[0];
            _wpfIsDumb = false;
        }
    }
}

public bool HasSelectionChanged(SelectionChangedEventArgs e)
{
    if (e.RemovedItems.Count > 0 && e.AddedItems.Count > 0)
        return true;
    else
        return false;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
215 views
Welcome To Ask or Share your Answers For Others

1 Answer

I found the solution. The selected index did not work. The problem was with the data. I was getting a NULL value passed to the box. Once I stripped out the NULL return from SQL, then it worked as expected.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

Just Browsing Browsing

[2] 怎么让ant的ant-message组件生成的元素在

548k questions

547k answers

4 comments

86.3k users

...