Click here to Skip to main content
15,890,282 members
Home / Discussions / C#
   

C#

 
GeneralRe: Toolbox icon for user control Pin
hain13-Mar-08 10:17
hain13-Mar-08 10:17 
GeneralRe: Toolbox icon for user control Pin
hain13-Mar-08 10:20
hain13-Mar-08 10:20 
GeneralUnable to connect to Web Service Pin
Manoj Sethi13-Mar-08 5:01
Manoj Sethi13-Mar-08 5:01 
GeneralRe: Unable to connect to Web Service Pin
Muhammad Gouda13-Mar-08 5:04
Muhammad Gouda13-Mar-08 5:04 
GeneralRe: Unable to connect to Web Service Pin
James J. Foster13-Mar-08 6:46
James J. Foster13-Mar-08 6:46 
GeneralRe: Unable to connect to Web Service Pin
Skippums13-Mar-08 6:46
Skippums13-Mar-08 6:46 
GeneralRe: Unable to connect to Web Service Pin
leppie13-Mar-08 10:57
leppie13-Mar-08 10:57 
GeneralErrors with typecasting Pin
Leo Smith13-Mar-08 4:55
Leo Smith13-Mar-08 4:55 
Hello,

I am having problems with a tree control in a windows form application. Sometime yesterday a typecast that I was using wuit functioning and I can't figure out where the problem started. I have a class that is an extents the System.Windows.Forms.TreeNode class. It adds fine to the TreeControl, but when I go back and try to read the object and cast it as the new class it throws the following exception. What could have happened to make this start failing? I am including the adding and the locating a node. The adding program sometimes throws a duplicate value, which is tested by the FindChildNode before adding it. The FindChildNode is the biggest problem right now and is throwing the following Exception (Bolded line is throwing the error).

Message="Unable to cast object of type 'System.Windows.Forms.TreeNode' to type 'InternalApp.ECDTreeNode'."

<br />
public class ECDTreeNode : System.Windows.Forms.TreeNode<br />
{<br />
.<br />
.<br />
.<br />
   public ECDTreeNode FindChildNode(string cText)<br />
   {<br />
      ECDTreeNode ret = null;<br />
      for (int i = 0; i < Nodes.Count; i++)<br />
      {<br />
         ECDTreeNode tn = (ECDTreeNode)Nodes[i];<br />
         if (cText.Trim().ToLower().CompareTo(tn.Text.Trim().ToLower()) == 0)<br />
         {<br />
            ret = tn;<br />
            break;<br />
         }<br />
      }<br />
      return ret;<br />
      }<br />
   }<br />
   public void AddSorted(ECDTreeNode tn)<br />
   {<br />
      bool bFound = false;<br />
      try<br />
      {<br />
         for (int i = 0; i < Nodes.Count; i++)<br />
         {<br />
            if (tn.Text.CompareTo(Nodes[i].Text) < 0)<br />
            {<br />
               Nodes.Insert(i, tn.Text.Trim());<br />
               bFound = true;<br />
               break;<br />
            }<br />
         }<br />
         if (!bFound)<br />
            Nodes.Add(tn);<br />
     }<br />
     catch (Exception e) <br />
     {<br />
        MessageBox.Show(e.Message, "Exception Error", <br />
             MessageBoxButtons.Ok, MessageBoxIcon.Error);<br />
     }<br />
   }<br />
<br />
}<br />
<br />


Thanks for any help,

Leo T. Smith
Program/Analyst Supervisor

GeneralRe: Errors with typecasting Pin
Gareth H13-Mar-08 5:04
Gareth H13-Mar-08 5:04 
GeneralRe: Errors with typecasting Pin
Leo Smith13-Mar-08 6:00
Leo Smith13-Mar-08 6:00 
GeneralRe: Errors with typecasting Pin
Skippums13-Mar-08 6:39
Skippums13-Mar-08 6:39 
GeneralRe: Errors with typecasting Pin
Gareth H13-Mar-08 6:47
Gareth H13-Mar-08 6:47 
GeneralRe: Errors with typecasting Pin
Skippums13-Mar-08 7:38
Skippums13-Mar-08 7:38 
GeneralRe: Errors with typecasting Pin
Leo Smith13-Mar-08 8:10
Leo Smith13-Mar-08 8:10 
GeneralRe: Errors with typecasting Pin
Gareth H13-Mar-08 8:17
Gareth H13-Mar-08 8:17 
GeneralPLEASE HELP ME Pin
ashutosh91113-Mar-08 4:24
ashutosh91113-Mar-08 4:24 
GeneralRe: PLEASE HELP ME Pin
Colin Angus Mackay13-Mar-08 4:51
Colin Angus Mackay13-Mar-08 4:51 
GeneralRe: PLEASE HELP ME Pin
phannon8613-Mar-08 5:00
professionalphannon8613-Mar-08 5:00 
GeneralRe: PLEASE HELP ME Pin
Gareth H13-Mar-08 5:14
Gareth H13-Mar-08 5:14 
GeneralRe: PLEASE HELP ME Pin
Paul Conrad13-Mar-08 10:42
professionalPaul Conrad13-Mar-08 10:42 
GeneralRe: PLEASE HELP ME Pin
snorkie13-Mar-08 11:12
professionalsnorkie13-Mar-08 11:12 
QuestionCount lines in rtf files with c# [modified] Pin
panoskatws13-Mar-08 4:10
panoskatws13-Mar-08 4:10 
GeneralRe: Count lines in rtf files with c# Pin
led mike13-Mar-08 4:20
led mike13-Mar-08 4:20 
GeneralRe: Count lines in rtf files with c# Pin
panoskatws13-Mar-08 7:41
panoskatws13-Mar-08 7:41 
GeneralRe: Count lines in rtf files with c# Pin
leppie13-Mar-08 4:20
leppie13-Mar-08 4:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.