[英]Selecting a default combobox value
When my program loads, my combobox has no default value. 当程序加载时,组合框没有默认值。 I want the first one to be the default value when the program is loaded.
我希望第一个成为程序加载时的默认值。 How can I do that?
我怎样才能做到这一点?
using Gtk;
using System;
class SharpApp : Window
{
Label label;
Label label2;
Label label3;
Label label4;
public SharpApp() : base(" VALUTASOFFAN")
{
SetDefaultSize(411, 199);
SetPosition(WindowPosition.Center);
SetIconFromFile("..\\..\\web.png");
DeleteEvent += new DeleteEventHandler(OnDelete);
string[] valutor = new string[]
{
"YEN",
"SEK",
"EURO"
};
//BOX1
Fixed fix = new Fixed();
ComboBox cb = new ComboBox(valutor);
ComboBox cb2 = new ComboBox(valutor);
Entry entry = new Entry ();
Entry entry2 = new Entry ();
cb.Changed += OnChanged;
cb2.Changed += OnChanged2;
entry.Changed += onChanged3;
entry2.Changed += onChanged4;
ComboBox combo = ComboBox.NewText();
combo.Active = 0
cb.Active = 0;
label = new Label("-");
label2 = new Label("-");
label3 = new Label("-");
label4 = new Label("-");
fix.Put(entry, 100, 30);
fix.Put(entry2, 100, 100);
fix.Put(cb, 300, 30);
fix.Put(cb2, 300, 100);
//fix.Put(label3, 10, 30);
//fix.Put(label4, 10, 100);
Add(fix);
ShowAll();
}
void OnChanged(object sender, EventArgs args)
{
ComboBox cb = (ComboBox) sender;
label.Text = cb.ActiveText;
}
void OnChanged2(object sender2, EventArgs args)
{
ComboBox cb2 = (ComboBox) sender2;
label2.Text = cb2.ActiveText;
}
void onChanged3(object sender3, EventArgs args)
{
Entry entry = (Entry)sender3;
label3.Text = entry.Text;
}
void onChanged4(object sender4, EventArgs args)
{
Entry entry2 = (Entry)sender4;
label4.Text = entry2.Text;
}
public static void Main()
{
Application.Init();
new SharpApp();
Application.Run();
}
void OnDelete(object obj, DeleteEventArgs args)
{
Application.Quit();
}
}
I want the first one to be the default value when the program is loaded.
我希望第一个成为程序加载时的默认值。 How can I do that?
我怎样才能做到这一点?
Base of index of the given items 给定项目的索引基数
yourComboBox.SelectedIndex = 0;
Base of .ValueMember
of the ComboBox
ComboBox
的.ValueMember
的基础
yourComboBox.SelectedValue = 1;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.