Solved

C# question

Posted on 2003-12-08
1
503 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 102
java  and programming certification ? 4 86
Apps blocked by Java 9 63
Auto-indent certain lines in Notepad++ 10 31
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
A short article about a problem I had getting the GPS LocationListener working.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now