Solved

C# question

Posted on 2003-12-08
1
505 Views
Last Modified: 2008-02-26
Let me start by saying I'm a total novice at C# programming, so any answers should be relatively self-explanatory.

I'm using VS .NET to try to create something loosely similiar to a windows help file - I have a treeview control on the left and a textarea on the right - when a user clicks on one of the nodes in the treeview the textarea should receive the corresponding data.

I actually have two questions -

1) All of the data for this project is being populated by a sql server db table, which i read into a dataset when the form is loaded - the table has ID, helptitle, and helptext fields.  The helptitle field ends up in the treeview nodes and the helptext field is what gets populated into the textarea when the helptitle node is clicked.  What's the best way to extract the helptext field given the ID field?  I'm currently using a dataview filter to get the correct row each time but I dont know if this is a 'best practice'.

2) More importantly, I'm having trouble with the event model - currently I have an event handler set up for the treeview's afterselect delegate(?) and I've also tried the selectvaluechanged.  It appears, however, that these events are firing several times even before the user has a chance to make a selection (when the form is initializing?)  This is causing problems because the event handler attempts to determine the value of the selected node (which in this case is a helpID) in order to get the corresponding helptext to populate the textarea.  When these events are firing, however, the value appears to be System.Data.something instead of the integer value I'm hoping for.

If you need me to post some code I'll try to do so.

Thanks
0
Comment
Question by:baal32
1 Comment
 
LVL 6

Accepted Solution

by:
valipotor earned 300 total points
ID: 9905876
1)
I suppose it's better to use a select statement
like this
"Select helptext from mytable where id=currentID"
to filter the records.
That way, you will get on the local host only the result, this will reduce network traffic.
But if you want a dinamic application, you should use DataView Filter as youu do.
b)
You can delegate your handler, after the form intialization has ended
like this:
private void Form1_Activated(object sender, System.EventArgs e)
{
                  
//here i delegate my handler to do it's work
      if (!added)
      {
            added=true;
            this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);;
      }
                  
}
You have to make sure you don't add the event twice, because the Form_Activated event is called each
time the window receives focus.
Te bool variable added is private and initialized to false.

I am using this event handler, and all works just fine, the text gets displayed corectlly

private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
      System.Windows.Forms.MessageBox.Show(e.Node.Text);
}
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 116
Hide vba in gp 7 104
Difference between List and Array in Python 5 93
Run AutoHotkey script directly from Notepad++ 5 61
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question