WPF中的组合框未显示for循环的值 [英] value of for loop is not displaying in combobox in wpf
本文介绍了WPF中的组合框未显示for循环的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void Window_Loaded_1(object sender, RoutedEventArgs e)
{
int ymax = 300;
parentchart.Axes.Add(new LinearAxis() { Minimum = 0, Orientation=AxisOrientation.Y, Maximum = ymax > 0 ? ymax : 500 });
for (int i = 0; i <= ymax; i++)
{
txty.Text = i.ToString();
cmb.Items.Add(i.ToString());
cmb.DisplayMemberPath = i.ToString();
}
i的值未显示在组合框中...
value of i is not displaying in combobox ...
推荐答案
删除行"cmb.DisplayMemberPath = i.ToString();"
您使用不正确的"DisplayMemberPath"
请检查此链接:
http://msdn.microsoft.com /en-us/library/system.windows.controls.itemscontrol.displaymemberpath(v=vs.100).aspx [
Remove the line "cmb.DisplayMemberPath = i.ToString();"
You are using incorrectly "DisplayMemberPath"
Please, check this link:
http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.displaymemberpath(v=vs.100).aspx[^]
private void Window_Loaded_1(object sender, RoutedEventArgs e)
{
List<int> lst = new List<int>() { 1,2,3,4,5,6,7,8,9,10};
cmbSelect.ItemsSource = lst; // first method
cmbSelect.SelectedIndex = 0;
(or)
foreach (var item in lst)//second method
{
cmbSelect.Items.Add(item);
}
cmbSelect.SelectedIndex = 0;
}
希望对您有帮助...
Hope it helps you ...
这篇关于WPF中的组合框未显示for循环的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文