Solved

C# question

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Replace a tag with sed 2 42
find a node in VST 2 47
noX challenge 17 76
pairs challenge 5 44
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…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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 …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

705 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

19 Experts available now in Live!

Get 1:1 Help Now