I have a TreeView that contains database objects that are basically folders. I want to be able to click on a "folder" in the tree and have it populate a set of controls with data about that "folder". While this all works fine with the code I've written, the issue is that using the arrow keys on the keyboard to go up and down the folder list will eventually hang the application. My assumption is that the background worker I am using to populate the controls is getting hung up.
I've searched and I can't find anything similar to my issue.
Here's my tree view afterselect code.
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 is a user control on the form. Here is the DisplayTrusteeList code
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");
}
}
And here is the background worker:
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;
}
}
I would like to be able to cursor through the tree nodes with the arrow keys and not have the after select code fire until the user lands on a node and stays there for a few seconds. Is that possible?
Thanks and this is my first question. Sorry if the format ins't great. I've used a lot of solutions from here.