当我的程序加载时,我的组合框没有默认值。我希望第一个在加载程序时成为默认值。我怎么能这样做?
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();
}
}
答案 0 :(得分:0)
我希望第一个是程序时的默认值 加载。我怎么能这样做?
给定项目的索引基础
yourComboBox.SelectedIndex = 0;
ComboBox
.ValueMember
的基础
yourComboBox.SelectedValue = 1;