C# code problem

Hi !!!

I have translated a VB code to C# code but i have problem as it gives me an error that i can not solve.
my code is :-

this.treeView1.Nodes(refEmp.Type).Nodes(refEmp.SSN);


Type and SSN are read only properties that return only

<b>: 'System.Windows.Forms.TreeView.Nodes' denotes a 'property' where a 'method' was expected</b>


Please help what could be wrong!!!!



Answer this question

C# code problem

  • jbanks27

    RKimble is correct, you can't have posted the entire line unless the line before it had a line continuation.

        Dim someValue As someThing = _
        treeView1.Nodes(refEmp.Type).Nodes(refEmp.SSN)

    Is that a node array you're trying to access

    VB:
        someValue = myArray(someItem)

    C#:
        someValue = myArray[someItem];

    () and [] tend to catch me out all the time.

  • Tom Issac

    Thanks for your reply..... you are correct i got caught in the same problem where i need to change the brackets type 

    this is the new code 

    this.treeView1.Nodes[(int)refEmp.type].Nodes[Convert.ToInt32(refEmp.SSN)];


    but the problem now it was complaining about the integert type should be in the bracket i treid to convert but got this error ... can you please help
    The error is :-
    <b>
     Only assignment, call, increment, decrement, and new object expressions can be used as a statement
    </b>

  • Brannon Jones

    No, you can't have the same code in VB... it would generate an error...

    The C# code:
    this.treeView1.Nodes(refEmp.Type).Nodes(refEmp.SSN);

    Would look like this in VB:
    treeView1.Nodes(refEmp.Type).Nodes(refEmp.SSN)

    But that line still doesn't <i>do</i> anything.  It is incomplete.  It would need to be something like:

    treeView1.Nodes(refEmp.Type).Nodes(refEmp.SSN).Toggle()
    or
    treeView1.Nodes(refEmp.Type).Nodes(refEmp.SSN) = New TreeViewNode
    or
    myNode = treeView1.Nodes(refEmp.Type).Nodes(refEmp.SSN)

    Otherwise the framework will generate the error "Property access must assign to the property or use its value."

    You also need to be sure that the values returned by refEmp.Type and refEmp.SSN are integers that represent a valid index in the nodes collections.

  • Lex1957

    i just wander when i write the code like below igot the error
    code:-


    treeView1.Nodes(refEmp.type).Nodes.Add(refEmp.SSN);


    Error:
    <b> 'System.Windows.Forms.TreeView.Nodes' denotes a 'property' where a 'method' was expected
    </b>

    please help ...i want to add a child node for a selected node ... this code is work fine in VB.NET but when translated t oC# got the error... please help

    Regards

    Fadil

  • dlamp

    >As you said, the code is not complete ... can you please tell me what i need to <b>Add</b>

    ;-)

  • summer

    I thought you had this solved

    I dont' think the code you just posted uses proper C# syntax...  Doesn't the index of the Nodes collection have to be wrapped in square brackets [] instead of parentheses ()

    treeView1.Nodes[refEmp.type].Nodes.Add(refEmp.SSN);


  • Jeff W

    As previously pointed out, that cannot be the full code. There must be a line continuation in the VB code.

    This code generates the error the error that you are recieving:
    this.treeView1.Nodes[(int)0].Nodes[Convert.ToInt32(0)];

    This code does not:
    TreeNode myNode = this.treeView1.Nodes[(int)0].Nodes[Convert.ToInt32(0)];

    In VB.net the error you would recieve is:
        Property access must assign to the property or use its value.

  • RickVF

    I don't think the () was a typo in the post.  The error he is getting would indicate that he has parentheses after Nodes; that's why the compiler is expecting a method.
  • alij

    Thanks again for your reply and thanks for being patient with me.... i might sounds stupid in my questions but i really appreciate your help....

    i will post the complete code for the VB and C# and make in dolb the line of the problem occur..... all what  itry to do is "Add the SSN string variable for a person to the Employee's Tree view control 

    VB code :-


    Public Class Form1
        Inherits System.Windows.Forms.Form

    #Region " Windows Form Designer generated code "

        Public Sub New()
            MyBase.New()

            'This call is required by the Windows Form Designer.
            InitializeComponent()

            'Add any initialization after the InitializeComponent() call

        End Sub

        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        Friend WithEvents TreeView1 As System.Windows.Forms.TreeView
        Friend WithEvents ListView1 As System.Windows.Forms.ListView
        Friend WithEvents Splitter1 As System.Windows.Forms.Splitter
        Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader3 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader4 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader5 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader6 As System.Windows.Forms.ColumnHeader
        Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
        Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
        Friend WithEvents mnuEmp As System.Windows.Forms.MenuItem
        Friend WithEvents mnuEmpNew As System.Windows.Forms.MenuItem
        Friend WithEvents mnuEmpDelete As System.Windows.Forms.MenuItem
        Friend WithEvents mnuEmpExit As System.Windows.Forms.MenuItem
        Friend WithEvents mnuReport As System.Windows.Forms.MenuItem
        Friend WithEvents mnuReportLast As System.Windows.Forms.MenuItem
        Friend WithEvents mnuReportSalary As System.Windows.Forms.MenuItem
        Friend WithEvents mnuHelp As System.Windows.Forms.MenuItem
        Friend WithEvents mnuHelpAbout As System.Windows.Forms.MenuItem
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.TreeView1 = New System.Windows.Forms.TreeView
            Me.ListView1 = New System.Windows.Forms.ListView
            Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
            Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader
            Me.ColumnHeader3 = New System.Windows.Forms.ColumnHeader
            Me.ColumnHeader4 = New System.Windows.Forms.ColumnHeader
            Me.ColumnHeader5 = New System.Windows.Forms.ColumnHeader
            Me.ColumnHeader6 = New System.Windows.Forms.ColumnHeader
            Me.Splitter1 = New System.Windows.Forms.Splitter
            Me.MainMenu1 = New System.Windows.Forms.MainMenu
            Me.mnuEmp = New System.Windows.Forms.MenuItem
            Me.mnuEmpNew = New System.Windows.Forms.MenuItem
            Me.mnuEmpDelete = New System.Windows.Forms.MenuItem
            Me.MenuItem4 = New System.Windows.Forms.MenuItem
            Me.mnuEmpExit = New System.Windows.Forms.MenuItem
            Me.mnuReport = New System.Windows.Forms.MenuItem
            Me.mnuReportLast = New System.Windows.Forms.MenuItem
            Me.mnuReportSalary = New System.Windows.Forms.MenuItem
            Me.mnuHelp = New System.Windows.Forms.MenuItem
            Me.mnuHelpAbout = New System.Windows.Forms.MenuItem
            Me.SuspendLayout()
            '
            'TreeView1
            '
            Me.TreeView1.Dock = System.Windows.Forms.DockStyle.Left
            Me.TreeView1.ImageIndex = -1
            Me.TreeView1.Location = New System.Drawing.Point(0, 0)
            Me.TreeView1.Name = "TreeView1"
            Me.TreeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Management"), New System.Windows.Forms.TreeNode("Union"), New System.Windows.Forms.TreeNode("Temps")})
            Me.TreeView1.Scrollable = False
            Me.TreeView1.SelectedImageIndex = -1
            Me.TreeView1.Size = New System.Drawing.Size(144, 366)
            Me.TreeView1.TabIndex = 0
            '
            'ListView1
            '
            Me.ListView1.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader3, Me.ColumnHeader4, Me.ColumnHeader5, Me.ColumnHeader6})
            Me.ListView1.Dock = System.Windows.Forms.DockStyle.Fill
            Me.ListView1.Location = New System.Drawing.Point(147, 0)
            Me.ListView1.Name = "ListView1"
            Me.ListView1.Size = New System.Drawing.Size(501, 366)
            Me.ListView1.TabIndex = 1
            Me.ListView1.View = System.Windows.Forms.View.Details
            '
            'ColumnHeader1
            '
            Me.ColumnHeader1.Text = "First"
            Me.ColumnHeader1.Width = 70
            '
            'ColumnHeader2
            '
            Me.ColumnHeader2.Text = "Last"
            Me.ColumnHeader2.Width = 72
            '
            'ColumnHeader3
            '
            Me.ColumnHeader3.Text = "SSN"
            Me.ColumnHeader3.Width = 81
            '
            'ColumnHeader4
            '
            Me.ColumnHeader4.Text = "Type"
            Me.ColumnHeader4.Width = 74
            '
            'ColumnHeader5
            '
            Me.ColumnHeader5.Text = "Salary"
            Me.ColumnHeader5.Width = 93
            '
            'ColumnHeader6
            '
            Me.ColumnHeader6.Text = "Hire Date"
            Me.ColumnHeader6.Width = 106
            '
            'Splitter1
            '
            Me.Splitter1.Location = New System.Drawing.Point(144, 0)
            Me.Splitter1.Name = "Splitter1"
            Me.Splitter1.Size = New System.Drawing.Size(3, 366)
            Me.Splitter1.TabIndex = 2
            Me.Splitter1.TabStop = False
            '
            'MainMenu1
            '
            Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuEmp, Me.mnuReport, Me.mnuHelp})
            '
            'mnuEmp
            '
            Me.mnuEmp.Index = 0
            Me.mnuEmp.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuEmpNew, Me.mnuEmpDelete, Me.MenuItem4, Me.mnuEmpExit})
            Me.mnuEmp.Text = "&Employee"
            '
            'mnuEmpNew
            '
            Me.mnuEmpNew.Index = 0
            Me.mnuEmpNew.Text = "&New..."
            '
            'mnuEmpDelete
            '
            Me.mnuEmpDelete.Index = 1
            Me.mnuEmpDelete.Text = "&Delete"
            '
            'MenuItem4
            '
            Me.MenuItem4.Index = 2
            Me.MenuItem4.Text = "-"
            '
            'mnuEmpExit
            '
            Me.mnuEmpExit.Index = 3
            Me.mnuEmpExit.Text = "E&xit"
            '
            'mnuReport
            '
            Me.mnuReport.Index = 1
            Me.mnuReport.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuReportLast, Me.mnuReportSalary})
            Me.mnuReport.Text = "&Report"
            '
            'mnuReportLast
            '
            Me.mnuReportLast.Checked = True
            Me.mnuReportLast.Index = 0
            Me.mnuReportLast.Text = "By &Last Name"
            '
            'mnuReportSalary
            '
            Me.mnuReportSalary.Index = 1
            Me.mnuReportSalary.Text = "By &Salary"
            '
            'mnuHelp
            '
            Me.mnuHelp.Index = 2
            Me.mnuHelp.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuHelpAbout})
            Me.mnuHelp.Text = "&Help"
            '
            'mnuHelpAbout
            '
            Me.mnuHelpAbout.Index = 0
            Me.mnuHelpAbout.Text = "&About..."
            '
            'Form1
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(648, 366)
            Me.Controls.Add(Me.ListView1)
            Me.Controls.Add(Me.Splitter1)
            Me.Controls.Add(Me.TreeView1)
            Me.Menu = Me.MainMenu1
            Me.Name = "Form1"
            Me.Text = "Acme HR App"
            Me.ResumeLayout(False)

        End Sub

    #End Region

        Private Sub mnuEmpNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEmpNew.Click
            ' Create and show the dialog box
            Dim frmNewEmp As New NewEmp()
            If frmNewEmp.ShowDialog() = DialogResult.Cancel Then _
                Return

            ' Create and initialize the employee object
            Dim refEmp As Employee
            refEmp = New Employee(frmNewEmp.txtFirst.Text, _
                frmNewEmp.txtLast.Text, frmNewEmp.txtSSN.Text, _
                CDec(frmNewEmp.txtSalary.Text), CType(frmNewEmp.cboType.SelectedIndex, empType), _
                frmNewEmp.HirePicker.Value)

            ' Add the employee's SSN to the TreeView
           <b> TreeView1.Nodes(refEmp.Type).Nodes.Add(refEmp.SSN)</b>
        End Sub
    End Class


    C# Code:-

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;

    namespace FadilCSharp
    {
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.TreeView treeView1;
    private System.Windows.Forms.Splitter splitter1;
    private System.Windows.Forms.ListView listView1;
    private System.Windows.Forms.ColumnHeader columnHeader1;
    private System.Windows.Forms.ColumnHeader columnHeader2;
    private System.Windows.Forms.ColumnHeader columnHeader3;
    private System.Windows.Forms.ColumnHeader columnHeader4;
    private System.Windows.Forms.ColumnHeader columnHeader5;
    private System.Windows.Forms.ColumnHeader columnHeader6;
    private System.Windows.Forms.MainMenu mainMenu1;
    private System.Windows.Forms.MenuItem menuItem1;
    private System.Windows.Forms.MenuItem menuItem2;
    private System.Windows.Forms.MenuItem menuItem3;
    private System.Windows.Forms.MenuItem menuItem4;
    private System.Windows.Forms.MenuItem menuItem5;
    private System.Windows.Forms.MenuItem menuItem6;
    private System.Windows.Forms.MenuItem menuItem7;
    private System.Windows.Forms.MenuItem menuItem8;
    private System.Windows.Forms.MenuItem menuItem9;
    private System.Windows.Forms.MenuItem menuItem10;
    private System.Windows.Forms.MenuItem menuItem11;
    private System.Windows.Forms.MenuItem menuItem12;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public Form1()
    {
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent();

    //
    // TODO: Add any constructor code after InitializeComponent call
    //
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.treeView1 = new System.Windows.Forms.TreeView();
    this.splitter1 = new System.Windows.Forms.Splitter();
    this.listView1 = new System.Windows.Forms.ListView();
    this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
    this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
    this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
    this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
    this.columnHeader5 = new System.Windows.Forms.ColumnHeader();
    this.columnHeader6 = new System.Windows.Forms.ColumnHeader();
    this.mainMenu1 = new System.Windows.Forms.MainMenu();
    this.menuItem1 = new System.Windows.Forms.MenuItem();
    this.menuItem2 = new System.Windows.Forms.MenuItem();
    this.menuItem3 = new System.Windows.Forms.MenuItem();
    this.menuItem4 = new System.Windows.Forms.MenuItem();
    this.menuItem5 = new System.Windows.Forms.MenuItem();
    this.menuItem6 = new System.Windows.Forms.MenuItem();
    this.menuItem7 = new System.Windows.Forms.MenuItem();
    this.menuItem8 = new System.Windows.Forms.MenuItem();
    this.menuItem9 = new System.Windows.Forms.MenuItem();
    this.menuItem10 = new System.Windows.Forms.MenuItem();
    this.menuItem11 = new System.Windows.Forms.MenuItem();
    this.menuItem12 = new System.Windows.Forms.MenuItem();
    this.SuspendLayout();
    // 
    // treeView1
    // 
    this.treeView1.Dock = System.Windows.Forms.DockStyle.Left;
    this.treeView1.ImageIndex = -1;
    this.treeView1.Location = new System.Drawing.Point(0, 0);
    this.treeView1.Name = "treeView1";
    this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
      new System.Windows.Forms.TreeNode("Management"),
      new System.Windows.Forms.TreeNode("Union"),
      new System.Windows.Forms.TreeNode("Temps")});
    this.treeView1.Scrollable = false;
    this.treeView1.SelectedImageIndex = -1;
    this.treeView1.Size = new System.Drawing.Size(121, 373);
    this.treeView1.TabIndex = 0;
    // 
    // splitter1
    // 
    this.splitter1.Location = new System.Drawing.Point(121, 0);
    this.splitter1.Name = "splitter1";
    this.splitter1.Size = new System.Drawing.Size(3, 373);
    this.splitter1.TabIndex = 1;
    this.splitter1.TabStop = false;
    // 
    // listView1
    // 
    this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
    this.columnHeader1,
    this.columnHeader2,
    this.columnHeader3,
    this.columnHeader4,
    this.columnHeader5,
    this.columnHeader6});
    this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
    this.listView1.Location = new System.Drawing.Point(124, 0);
    this.listView1.Name = "listView1";
    this.listView1.Size = new System.Drawing.Size(444, 373);
    this.listView1.TabIndex = 2;
    this.listView1.View = System.Windows.Forms.View.Details;
    this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
    // 
    // columnHeader1
    // 
    this.columnHeader1.Text = "First";
    // 
    // columnHeader2
    // 
    this.columnHeader2.Text = "Last";
    // 
    // columnHeader3
    // 
    this.columnHeader3.Text = "SSN";
    // 
    // columnHeader4
    // 
    this.columnHeader4.Text = "Type";
    // 
    // columnHeader5
    // 
    this.columnHeader5.Text = "Salary";
    // 
    // columnHeader6
    // 
    this.columnHeader6.Text = "Hire Date";
    // 
    // mainMenu1
    // 
    this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
      this.menuItem1,
      this.menuItem6,
      this.menuItem11});
    // 
    // menuItem1
    // 
    this.menuItem1.Index = 0;
    this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
      this.menuItem2,
      this.menuItem3,
      this.menuItem4,
      this.menuItem5});
    this.menuItem1.Text = "&Employee";
    // 
    // menuItem2
    // 
    this.menuItem2.Index = 0;
    this.menuItem2.Text = "&New";
    this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
    // 
    // menuItem3
    // 
    this.menuItem3.Index = 1;
    this.menuItem3.Text = "&Delete";
    // 
    // menuItem4
    // 
    this.menuItem4.Index = 2;
    this.menuItem4.Text = "-";
    // 
    // menuItem5
    // 
    this.menuItem5.Index = 3;
    this.menuItem5.Text = "E&xit";
    // 
    // menuItem6
    // 
    this.menuItem6.Index = 1;
    this.menuItem6.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
      this.menuItem7,
      this.menuItem8,
      this.menuItem9,
      this.menuItem10});
    this.menuItem6.Text = "&Report";
    // 
    // menuItem7
    // 
    this.menuItem7.Checked = true;
    this.menuItem7.Index = 0;
    this.menuItem7.Text = "By &Last Name";
    // 
    // menuItem8
    // 
    this.menuItem8.Index = 1;
    this.menuItem8.Text = "By &Salary";
    // 
    // menuItem9
    // 
    this.menuItem9.Index = 2;
    this.menuItem9.Text = "&Find";
    // 
    // menuItem10
    // 
    this.menuItem10.Index = 3;
    this.menuItem10.Text = "Save as &XML";
    // 
    // menuItem11
    // 
    this.menuItem11.Index = 2;
    this.menuItem11.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
       this.menuItem12});
    this.menuItem11.Text = "&Help";
    // 
    // menuItem12
    // 
    this.menuItem12.Index = 0;
    this.menuItem12.Text = "&About";
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(568, 373);
    this.Controls.Add(this.listView1);
    this.Controls.Add(this.splitter1);
    this.Controls.Add(this.treeView1);
    this.Menu = this.mainMenu1;
    this.Name = "Form1";
    this.Text = "Acme HR App";
    this.ResumeLayout(false);

    }
    #endregion

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    ///[STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    }

    private void menuItem2_Click(object sender, System.EventArgs e)
    {
    NewEmp frmNewEmp = new NewEmp();
    if (frmNewEmp.ShowDialog() == DialogResult.Cancel)
    return;
    Employee refEmp; 
    refEmp = new Employee(frmNewEmp.txtFirst.Text,frmNewEmp.txtLast.Text, frmNewEmp.txtSSN.Text,System.Convert.ToDecimal(frmNewEmp.txtSalary.Text), ((empType)frmNewEmp.cboType.SelectedIndex),frmNewEmp.HirePicker.Value);
    <b>this.treeView1.Nodes[(int)refEmp.type].Nodes[Convert.ToInt32(refEmp.SSN)];</b>


    }


    }
    }


    As you said, the code is not complete ... can you please tell me what i need to add

  • JonesEJ20

    That is an imcomplete line of code.  You are accessing a property without using its value.

    You need to either be calling a method on .Nodes(refEmp.SSN), setting it equal to something, or setting somthing equal to it.

  • methylamine

    Hi !!

    Thanks for your reply.....

    but i have the same code in VB.NET  it works fine without errors and i just translate it to C# the property is read only (return) can you please help me more and give me hint as i am new user for the C#...i really apprecaite your help.

  • freekyzolte

    As far as I can see, there is nothing wrong with the code that you have posted. Obviously there is a lot of code that you have not posted (other forms aswell as enums and structures), and the error lies somewhere there.

    What type is refEmp.SSN
    If it's a string type then it should work OK.

    What value does refEmp.type have when the error occurs
    If you only have 3 root nodes then it should always be either 0, 1 or 2.

    We need more information than you're giving in order to help, but at the same time, we don't want to see your whole project.

    Put a breakpoint on that line of code and find out what the values of refEmp.type and refEmp.SSN are when the error occurs.

    I'm assuming that the () around the Nodes is a typo.

  • eebarroso

    Hi !!

    Thank you both for your help and being patient with me....it seems t obe solved now with the following code

    treeView1.Nodes[Convert.ToInt32(refEmp.type)].Nodes.Add(refEmp.SSN);

    But still i ma having problem ... i have in the treeview three nodes: Management, Union and Temp... in my form everytime you can add the new employee in the form and you should select the type of employee from the Drop down menu and once you click ok you got the employee listed beneath the type chosen.... now the proble m is when i add the first employee for the type: Temp or any other ... it is OK but when i add a second Employee to the same Type i give error signaling on the code above and seems to be it is not correct 100% can you please tell me how t osolve it   i appreciate your help.

    Regards

    Fadil 

  • Nazar Kuliev

    The VB example:
    TreeView1.Nodes(refEmp.Type).Nodes.Add(refEmp.SSN)

    is calling the Add() method on the Nodes collection.  That's why it is a complete statement.  It looks like you're just missing the Add() method in your C# translation:


    this.treeView1.Nodes[(int)refEmp.type].Nodes<b>.Add(</b>[Convert.ToInt32(refEmp.SSN)]);


    Now, I'm not sure about the ( ) around the value you want to add...  have a C# person confirm the syntax... 

  • C# code problem