Listview selectionchanged两次火灾,如何控制?

时间:2014-07-31 15:51:12

标签: c# listview selectedindexchanged

显示表格后,此加载egain。我知道这是设计的。但我不想再表演了。

    private void HandleLSVVacunacion_SelectedIndexChanged(object sender, EventArgs e)
    {
        ListView SourceControl = (ListView)sender;

        if (SourceControl.SelectedItems.Count > 0)
        {
            int IdVacunacion = Convert.ToInt32(LSVVacunacion.SelectedItems[0].SubItems[0].Text.Trim());
            Formularios.FrmVacunacion f = new Formularios.FrmVacunacion();
            f.ID = IdVacunacion;
            f.HC = hc;
            f.ShowDialog();
            CargarEsquemaVacunacion(); // reload The ListView with changes; and show again the form!

        }

    }

1 个答案:

答案 0 :(得分:0)

如果CargarEsquemaVacunacion中的代码导致重新输入事件处理程序,则可以删除事件处理程序,重新加载列表并重新应用事件处理程序

    if (SourceControl.SelectedItems.Count > 0)
    {
        .....
        f.ShowDialog();
        try
        {
            LSVVacunacion.SelectedIndexChanged -= HandleLSVVacunacion_SelectedIndexChanged;
            CargarEsquemaVacunacion(); 
        }
        finally
        {
            LSVVacunacion.SelectedIndexChanged += HandleLSVVacunacion_SelectedIndexChanged;
        }

    }

请注意,此代码位于try / finally块内,以确保在异常的情况下将事件处理程序重新应用于事件SelectedIndexChanged

相关问题