T
Tony
Hello!
I have a TreeView where I have added one TreeNode which is named Country and
below this country node I have added several TreeNode which are different
countries such as Sweden, Norway ,Polen and so on.
I have also a ContextMenuStrip with one item added which is Statistics.
So when I right click on for example Sweden or Norway or Polen the context
meny with Statictics is displayed so this works good.
In method AddCountries below I have added this row
node.ContextMenuStrip = textBoxMenu;
Now to my problem when I right click on any county(Sweden, Norway ,Polen )
and then choose Statistics I must
be able to find which country I have clicked on. I have made an attempt to
solve this in method textBoxMenu_Opening and method
GetStatisticContext_Click.
In method textBoxMenu_Opening I have hoped by using SourceControl in this
way
this.Tag = ((ContextMenuStrip)sender).SourceControl;
to be able to get the TreeNode I clicked on and save it in the Tag for the
form.
So when I click on Statistics eventHandler GetStatisticContext_Click is
called
and here I have hoped by using the result in Tag to know which TreeNode I
have clicked on.
This doesn's work so I hope that somebody can make any suggestion where to
change so I can get it
to work.
public partial class TimeFlowMDIForm : Form
{
....
public TimeFlowMDIForm() : base()
{
InitializeComponent();
treeView.Nodes.Add(CreateCountryView());
}
private TreeNode CreateCountryView()
{
TreeNode Country = new TreeNode();
Country.Name = "Country";
Country.Text = "Country";
AddCountries(ref Country);
return Country;
}
private void AddCountries(ref TreeNode parent)
{
ds = DA.GetAllRowsForTable(connectionString, "Country");
if (Primer.Common.Data.DataSet.HasData(ds))
{
foreach (DataRow row in ds.Tables[0].Rows)
{
TreeNode node = new TreeNode();
node.ContextMenuStrip = textBoxMenu;
node.Name = row["CountryId"].ToString();
node.Text = row["Name"].ToString();
parent.Nodes.Add(node);
}
}
}
private void textBoxMenu_Opening(object sender, CancelEventArgs e)
{
this.Tag = ((ContextMenuStrip)sender).SourceControl;
}
private void GetStatisticContext_Click(object sender, EventArgs e)
{
Type slask2 = sender.GetType();
string slask = this.Tag.ToString();
}
//Tony
I have a TreeView where I have added one TreeNode which is named Country and
below this country node I have added several TreeNode which are different
countries such as Sweden, Norway ,Polen and so on.
I have also a ContextMenuStrip with one item added which is Statistics.
So when I right click on for example Sweden or Norway or Polen the context
meny with Statictics is displayed so this works good.
In method AddCountries below I have added this row
node.ContextMenuStrip = textBoxMenu;
Now to my problem when I right click on any county(Sweden, Norway ,Polen )
and then choose Statistics I must
be able to find which country I have clicked on. I have made an attempt to
solve this in method textBoxMenu_Opening and method
GetStatisticContext_Click.
In method textBoxMenu_Opening I have hoped by using SourceControl in this
way
this.Tag = ((ContextMenuStrip)sender).SourceControl;
to be able to get the TreeNode I clicked on and save it in the Tag for the
form.
So when I click on Statistics eventHandler GetStatisticContext_Click is
called
and here I have hoped by using the result in Tag to know which TreeNode I
have clicked on.
This doesn's work so I hope that somebody can make any suggestion where to
change so I can get it
to work.
public partial class TimeFlowMDIForm : Form
{
....
public TimeFlowMDIForm() : base()
{
InitializeComponent();
treeView.Nodes.Add(CreateCountryView());
}
private TreeNode CreateCountryView()
{
TreeNode Country = new TreeNode();
Country.Name = "Country";
Country.Text = "Country";
AddCountries(ref Country);
return Country;
}
private void AddCountries(ref TreeNode parent)
{
ds = DA.GetAllRowsForTable(connectionString, "Country");
if (Primer.Common.Data.DataSet.HasData(ds))
{
foreach (DataRow row in ds.Tables[0].Rows)
{
TreeNode node = new TreeNode();
node.ContextMenuStrip = textBoxMenu;
node.Name = row["CountryId"].ToString();
node.Text = row["Name"].ToString();
parent.Nodes.Add(node);
}
}
}
private void textBoxMenu_Opening(object sender, CancelEventArgs e)
{
this.Tag = ((ContextMenuStrip)sender).SourceControl;
}
private void GetStatisticContext_Click(object sender, EventArgs e)
{
Type slask2 = sender.GetType();
string slask = this.Tag.ToString();
}
//Tony