Dan, thanks. The fact that AfterSelect fires once for a node, renders this
option useless for my needs. i've attached the gist of my code so that you
can see (maybe) why the SelectAfter event loops through all nodes...
/// <summary>
/// Routine for loading CRF Form.
/// </summary>
/// <param name="sSubjectId"></param>
private void LoadCRFSelectionForm()
{
// Dispose of previously created controls
DisposeDynamicControls();
panelMain.Controls.Clear();
panelMain.BackColor = System.Drawing.Color.White;
// Set Bool to False: Default (Impossible to reach this form w/out having
selected a subject previously)
bIsNewSubject = false;
// Define Contorls
Label lblCode = new Label();
TreeView treeVisits = new TreeView();
Label lblDiagnostic = new Label();
Label lblDesc = new Label();
ImageButton btnSubmit = new ImageButton();
ImageButton btnBack = new ImageButton();
ImageList imgList = new ImageList();
// Set the properties for the controls
lblCode.Size = new System.Drawing.Size(200, kLabelMinHeight);
lblCode.Location = new System.Drawing.Point(kLeftMargin, kTopMargin);
lblCode.Text = "Subject: " + sSubjectId;
lblCode.Font = kFontSmallBold;
lblCode.ForeColor = kDarkRed;
lblDesc.Size = new System.Drawing.Size(panelMain.Width, kLabelMaxHeight);
lblDesc.Location = new System.Drawing.Point(kLeftMargin, lblCode.Bottom +
kControlVSpacing);
lblDesc.Text = "Tap a visit to continue:";
lblDesc.Font = kFontSmall;
imgList.Images.Add(((System.Drawing.Image)(new
Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("VivoSC.images.status_tobecompleted.gif")))));
imgList.Images.Add(((System.Drawing.Image)(new
Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("VivoSC.images.status_incomplete.gif")))));
imgList.Images.Add(((System.Drawing.Image)(new
Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("VivoSC.images.status_check.gif")))));
imgList.Images.Add(((System.Drawing.Image)(new
Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("VivoSC.images.subject_data.gif")))));
imgList.ImageSize = new System.Drawing.Size(16, 16);
treeVisits.Size = new System.Drawing.Size(200, 100);
treeVisits.Location = new System.Drawing.Point(kLeftMargin,
lblDesc.Bottom);
treeVisits.Font = kFontSmall;
treeVisits.ImageList = imgList;
treeVisits.ShowLines = true;
treeVisits.ShowPlusMinus = false;
treeVisits.ShowRootLines = true;
treeVisits.AfterSelect += new
System.Windows.Forms.TreeViewEventHandler(AfterSelect);
// Generate list of Visits & bind to TreeView control
DataSet ds_Visit = utilities.fGetSubjectVisits(iStudyId, sSubjectId);
DataSet ds_CRF = utilities.fGetSubjectCRFs(iStudyId, sSubjectId);
int iPN = 0; // Counter for Parent Node
foreach (DataRow rV in ds_Visit.Tables["SubjectVisits"].Rows)
{
// code to create notes
}
// Add Tree Node for New patient Data
treeVisits.Nodes.Insert(0, (new TreeNode("Subject Data")));
treeVisits.Nodes[0].ImageIndex = 3;
treeVisits.Nodes[0].SelectedImageIndex = 3;
// Buttons continuar y volver.
btnSubmit.Image = new
Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("VivoSC.images.continuar.gif"));
btnSubmit.Image_On = new
Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("VivoSC.images.continuar_click.gif"));
btnSubmit.Size = new Size(78, 16);
btnSubmit.Location = new Point(treeVisits.Right - btnSubmit.Width, 160);
btnSubmit.Click += new EventHandler(LoadNewVisitForm);
btnBack.Image = new
Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("VivoSC.images.buscar.gif"));
btnBack.Image_On = new
Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("VivoSC.images.buscar_click.gif"));
btnBack.Size = new Size(65, 16);
btnBack.Location = new Point(btnSubmit.Left - btnBack.Width, 160);
btnBack.Click += new EventHandler(LoadSearchForm);
// Set Panel Main & PicBox
panelMain.Height = 190;
picBox.Image = new
Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("VivoSC.images.vivo_edc.gif"));
// Set Nav Bar
lblTopNavBar.Text = "Clinical Data";
lblTopNavBar.Visible = true;
// Set Help
panelHelp.Visible = true;
iHelpMsg = 1;
// panel main
panelMain.Controls.Add(lblCode);
panelMain.Controls.Add(treeVisits);
panelMain.Controls.Add(btnSubmit);
panelMain.Controls.Add(btnBack);
panelMain.Controls.Add(lblDesc);
panelMain.Controls.Add(btnNewVisit);
}
/// <summary>
/// Tap event - executed after selecting a CRF in the TreeView control
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AfterSelect(object sender,
System.Windows.Forms.TreeViewEventArgs e)
{
if (e.Action == TreeViewAction.Unknown) return;
// Edit Subject Data (Load Subject Data Form)
if (((TreeViewEventArgs)e).Node.Text == "Subject Data")
{
LoadSubjectDataForm();
return;
}
// Get the string name of the actual study exam
else if (((TreeViewEventArgs)e).Node.Text.IndexOf("Visit") < 0)
{
// Declare local vars
string[] ar_Tag = new string[5];
// string sVisitName = ((TreeView)ctr).SelectedNode.Parent.Text;
ar_Tag = (string[])((TreeView)sender).SelectedNode.Tag;
// do something...
}
// TreeViewCancelEventArgs tvc = new TreeViewCancelEventArgs(e.Node, true,
e.Action);
}
Daniel Moth said:
There is no Click event; AfterSelect is your only option unfortunately.
Vote
for NodeMouseClick to be supported in CF 2.0:
http://lab.msdn.microsoft.com/produ...edbackid=8bb0f504-037b-4c81-aea0-dfcd25185a43
AfterSelect will fire once for a node when it gets selected. The only
problem is that once it is selected you get no more events when the user
taps on it again.
I don't see the "loop through all of my nodes" behaviour you describe.
Can
you post a sample that exhibits this behaviour?
Cheers
Daniel