在树视图中选择树节点以填充表单中的数据是挂起的

本文关键字:表单 挂起 数据 填充 视图 选择 树节点 | 更新日期: 2023-09-27 17:59:03

我有一个TreeView,它包含基本上是文件夹的数据库对象。我希望能够点击树中的"文件夹",并让它用有关该"文件夹"的数据填充一组控件。虽然这一切与我编写的代码配合得很好,但问题是使用键盘上的箭头键在文件夹列表中上下移动最终会挂起应用程序。我的假设是,我用来填充控件的后台工作人员被挂断了。

我已经搜索过了,找不到任何与我的问题类似的内容。

这是我选择代码后的树视图。

private void dmTree_AfterSelect(object sender, TreeViewEventArgs e)
    {
        object[] tagParts = e.Node.Tag as object[];
        SelectedFolderNumber = tagParts[1].ToString();
        if (!String.IsNullOrEmpty(SelectedFolderNumber) && SelectedFolderNumber != "0")
        {
            //update mini profile
            if (bgwMiniProfile.IsBusy)
            {
                bgwMiniProfile.CancelAsync();
            }
            while (bgwMiniProfile.CancellationPending)
            {
                Application.DoEvents();
            }
            bgwMiniProfile.RunWorkerAsync();
            while (bgwMiniProfile.IsBusy)
            {
                Application.DoEvents();
            }
            securityPanel.DisplayTrusteeList(folderTrustees);
        }
    }

securityPanel是表单上的一个用户控件。这是DisplayTrusteeList代码

public void DisplayTrusteeList(List<DocumentTrustee> documentTrustees)
    {
        try
        {
            dgvTrustees.Rows.Clear();
            foreach (DocumentTrustee dt in documentTrustees)
            {
                dgvTrustees.Rows.Add(imagePG.Images[(int)dt.TrusteeType], dt.GetFullName(dmLogin), dt.AccessRights);
            }
            foreach (DataGridViewRow myRow in dgvTrustees.Rows)
            {
                ValidateRights(int.Parse(myRow.Cells["dmRights"].Value.ToString()), myRow);
            }
            dgvTrustees.ClearSelection();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "DisplayTrusteeList");
        }
    }

这是后台工作人员:

private void bgwMiniProfile_DoWork(object sender, DoWorkEventArgs e)
    {
        if (!bgwMiniProfile.CancellationPending)
        {
            SetText(txtDocNumber, SelectedFolderNumber);
            SetText(txtDocName, Utility.GetProfileValue(adminLogin, SelectedFolderNumber, "DOCNAME"));
            SetText(txtClientId, Utility.GetProfileValue(adminLogin, SelectedFolderNumber, "CLIENT_ID"));
            SetText(txtClientName, Utility.SetDescription(adminLogin, "CLIENT", txtClientId.Text));
            SetText(txtMatterId, Utility.GetProfileValue(adminLogin, SelectedFolderNumber, "MATTER_ID"));
            SetText(txtMatterName, Utility.SetDescription(adminLogin, "CLIENT", txtClientId.Text, txtMatterId.Text));
            folderTrustees = Utility.GetFolderTrustees(adminLogin, SelectedFolderNumber);
        }
        else
        {
            e.Cancel = true;
        }
    }

我希望能够用箭头键在树节点中移动光标,并且在用户降落在节点上并在那里停留几秒钟之前,不会触发后选择代码。这可能吗?

谢谢,这是我的第一个问题。如果格式不太好,很抱歉。我在这里使用了很多解决方案。

在树视图中选择树节点以填充表单中的数据是挂起的

我找到了一个更好的方法。我使用的不是AfterSelect,而是NodeMouseClick。这反映了Windows资源管理器的功能。现在,用户可以在文件夹树中上下移动光标,而不会出现任何问题。右侧的数据只有在单击节点时才会填充。这对我来说非常有效。