Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C# question

Posted on 2003-12-08
1
Medium Priority
?
509 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 1200 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Six Sigma Control Plans
Introduction to Processes

604 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