drop down menu - WPF ComboBox bad blank value -
I have a WPF combo box that is linked to a set of data. I do not have permission to modify the controls directly, nor can I change the data
I am returning 1 item to my combo box, but there are actually 2 rows; Both the blank line and my expected value have an index value of 0. I do not want to see this blank line, only my expected data in the combo box auto-selection I've looked through all related posts here, but any solution in my case did not work I was doing programming for a long time, but now thanks to a new help for WPF.
XML
& lt; Maikomboboks 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 task = sender as MyComboBox; If (job! = Null and amp; function. Hasis Chenbd (e)) {int compTmplId = int.Parse (work.SelectedValue.ToString ()); If (! _wpfIsDumb & ChangeComponent (compTmplId)) {_wpfIsDumb = true; work. Selected ITem = E. Deleted [0]; _wpfIsDumb = False; }}} Public bool HasSelectionChanged (SelectionChangedEventArgs e) {if (e.RemovedItems.Count & gt; 0 & amp; & amp; e.AddedItems.Count & gt; 0) return true; Second false return; } You can achieve this feat by setting 0 SelectedIndex.
XAML:
& lt; ComboBox name = "myCB" SelectedIndex = "0" MaxWidth = "200" maxHeight = "25" /> Code-Back:
Namespace nsComboBox {/// & LT; Summary & gt; /// MainWindow.xaml for Interaction Logic /// & lt; / Summary & gt; Public Partial Class Main Window: Window {Public Main Window () {Initial Group (); MyCB.Items.Add ("Item 1"); MyCB.Items.Add ("Item 2"); MyCB.Items.Add ("Item 3"); MyCB.SelectedIndex = 0; }}}
Comments
Post a Comment