设置DataSource时,不会触发Listbox,SelectedIndexChanged

时间:2013-07-29 18:23:39

标签: c# winforms listbox datasource selection

我使用days字段(BindingList<Day>)作为DataSource ListBox。我有一段代码:

if (seasonId >= 0)
{
    context.DbPerform((SQLiteConnection connection) =>
    {
        foreach (var item in DBProcessor.DBSelectCustom(
                connection,
                "SELECT * FROM Days WHERE SeasonId=@seasonId;",
                (SQLiteCommand cmd) =>
        {
               var seasonIdParam = cmd.CreateParameter();
               seasonIdParam.ParameterName = "@seasonId";
               seasonIdParam.Value = seasonId;
               cmd.Parameters.Add(seasonIdParam);
         },
         DayFactory.Instance))
         {
               days.Add(item);
         }
     });
}

我已经检查了调试器,days.Add(item); ListBox的{​​{1}}从-1更改为0.但是,没有SelectedIndex事件被触发。为什么?我做错了吗?

0 个答案:

没有答案