Solved

C# question

Posted on 2003-12-08
1
507 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This is an explanation of a simple data model to help parse a JSON feed
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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 …
Progress

688 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