我有一个组合框,它有SelectedIndexChanged事件,但我想在某些情况下忽略该事件如何实现该功能。
描述代码如下
private void Form1_Load(object sender, EventArgs e)
{
List<string> lstString = new List<string>();
lstString.Add("One");
lstString.Add("Two");
lstString.Add("Three");
foreach (string str in lstString)
cBox.Items.Add(str);
//Here I want Ignore cbox_SelectedIndexChanged Event
cBox.SelectedIndex = 0;
}
private void cBox_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("Your Selected Item is :- " + cBox.SelectedItem.ToString());
}
答案 0 :(得分:1)
您可以选择2种方法中的任何一种。
Then model is valid:
| Id | Children[0].Id | Children[0].Name | Children[0].Length | Children[1].Id | Children[1].Name | Children[1].Length |
| 1 | 222 | Name0 | 5 | 223 | Name1 | 6 |
方法[Then]
public void Then_Model_Is_Valid(MyObject myObject)
{
// use your binded object here
}
[StepArgumentTransformation]
public MyObject MyObjectTransform(Table table)
{
var modelState = new ModelStateDictionary();
var model = new MyObject();
var state = TryUpdateModel(model, table.Rows[0].ToDictionary(pair => pair.Key, pair => pair.Value), modelState);
return model;
}
后才能订阅活动,如果这是唯一的情况。答案 1 :(得分:1)
不是在设计器中订阅事件(我希望你现在这样做),你可以在初始化完成后在代码中订阅事件。
private void Form1_Load(object sender, EventArgs e)
{
// Init stuff
cBox.SelectedIndex = 0;
// Event subscription
cBox.SelectedIndexChanged += cBox_SelectedIndexChanged;
}
private void cBox_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("Your Selected Item is :- " + cBox.SelectedItem.ToString());
}