0

我有一个 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;
        }
    }

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

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

4

1 回答 1

0

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

于 2016-07-29T17:35:18.557 回答