Access treeView.selectednode from another form

  • Thread starter Thread starter rhaazy
  • Start date Start date
R

rhaazy

Using C# and VS 2003

I have two forms and a treeView, the treeView is on Form1

On Form1

Form frmAddOrgSystem = new frmAddOrgSystem();
frmAddOrgSystem.ShowDialog();

on frmAddOrgSystem

orgsystemid = Form1.treeView2.SelectedNode.Index.ToString();

I get this error:

An object reference is required for the nonstatic field... etc etc

I know I need to do something like pass a reference of Form1 to
frmAddOrgSystem, but I cant find any real clear eample of this online,
any help would be appreciated!
 
rhaazy said:
Using C# and VS 2003

I have two forms and a treeView, the treeView is on Form1

On Form1

Form frmAddOrgSystem = new frmAddOrgSystem();
frmAddOrgSystem.ShowDialog();

on frmAddOrgSystem

orgsystemid = Form1.treeView2.SelectedNode.Index.ToString();

I get this error:

An object reference is required for the nonstatic field... etc etc

I know I need to do something like pass a reference of Form1 to
frmAddOrgSystem, but I cant find any real clear eample of this online,
any help would be appreciated!

I usually do this this way:

public class frmAddOrgSystem : Form
{
private string _orgSystemId = "";

public string OrgSystemId
{
get { return this._orgSystemId; }
set
{
if (value == null) throw new
ArgumentNullException("value");
this._orgSystemId = value;
}
}
}

then in Form1:

frmAddOrgSystem addForm = new frmAddOrgSystem();
addForm.OrgSystemId = this.treeView2.SelectedNode.Index.ToString();
addForm.ShowDialog();
....
 
thx
Bruce said:
I usually do this this way:

public class frmAddOrgSystem : Form
{
private string _orgSystemId = "";

public string OrgSystemId
{
get { return this._orgSystemId; }
set
{
if (value == null) throw new
ArgumentNullException("value");
this._orgSystemId = value;
}
}
}

then in Form1:

frmAddOrgSystem addForm = new frmAddOrgSystem();
addForm.OrgSystemId = this.treeView2.SelectedNode.Index.ToString();
addForm.ShowDialog();
...
 
Back
Top