|
hello everybody!!
iam generating a windows form which has a treeview at the left and a splitpanel at its right.
the treeview consists of 3 parent nodes with 1 child node in each parent node. the parent nodes have a contextmenu with "Start" and "Stop" as menu items and child nodes have a contextmenu with "Properties" as menuitem.
each of the menuitem has an OnClick event handler.
what i want is, on clicking the menuitem of each of the child nodes, a different panel should be displayed each time. for this, i need to have 3 panels, one for each childnode. when one panel is being displayed, others should be hidden. my requirement is something similar to the WindowsExplorer, but iam not able to generate the desired o/p.
Also, when i right-click on any of the node, the contextmenu is displayed, but after clicking the desired menuitem, the contextmenu just doesnt disappear.
am i missing some property tat has to be set for the contextmenu to disappear after selecting a menuitem?
this is a part of my code:
mnuParentMenu.MenuItems.Add(0, new MenuItem("Start", new System.EventHandler(mnuStart_Click)));<br />
mnuParentMenu.MenuItems.Add(1, new MenuItem("Stop", new System.EventHandler(mnuStop_Click)));<br />
mnuChildMenu.MenuItems.Add(0, = new MenuItem("Properties", new System.EventHandler(mnuPropertiesC_Click)));<br />
<br />
TreeNode node = new TreeNode("Parent");<br />
node.Tag = "ParentNodeMenu";<br />
node.ContextMenu = mnuParentMenu;<br />
treeView1.Nodes.Add(node);<br />
node = new TreeNode("Child");<br />
node.Tag = "ChildNodeMenu";<br />
node.ContextMenu = mnuChildMenu;<br />
treeView1.Nodes[0].Nodes.Add(node);
I would be thankful to all who wish to take some time and help me out.
Sonu
|
|
|
|
|
Sonu.T wrote: what i want is, on clicking the menuitem of each of the child nodes, a different panel should be displayed each time. for this, i need to have 3 panels, one for each childnode. when one panel is being displayed, others should be hidden. my requirement is something similar to the WindowsExplorer, but iam not able to generate the desired o/p.
How have you implemented it currently and what happens if you click on a child node? Simply setting the Visible property of the panel to be hidden to false and sending it to the back of the ZOrder using SendToBack should work fine, I think. Another approach would be to have a single panel, but different UserControl derived classes. That way, designing the UI would be easier.
Sonu.T wrote: Also, when i right-click on any of the node, the contextmenu is displayed, but after clicking the desired menuitem, the contextmenu just doesnt disappear.
I'm surprised that you even get the context menu. This[^] KB article shows how to add multiple context menus for different nodes to treeviews. Basically, you subscribe to the MouseUp event, get the point where the mouse was clicked, use the GetNodeAt method to get the TreeNode at that point and then show the appropriate popup menu.
|
|
|
|
|
hello Senthil
thanx for replying.
i understand that there is no clarity in my query....
iam pasting my entire code here...hope this wud make better sense
public partial class Form1 : Form<br />
{<br />
private System.Windows.Forms.ContextMenu mnuParentMenu = new System.Windows.Forms.ContextMenu();<br />
private System.Windows.Forms.ContextMenu mnuChildMenu = new System.Windows.Forms.ContextMenu();<br />
private MenuItem mnuStart;<br />
private MenuItem mnuStop;<br />
private MenuItem mnuProperties;<br />
private MenuItem mnuPropertiesC;<br />
private TreeNode m_OldSelectNode;<br />
private TreeNode node;<br />
<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{ <br />
mnuParentMenu.MenuItems.Add(0, mnuStart = new MenuItem("Start", new System.EventHandler(mnuStart_Click)));<br />
mnuParentMenu.MenuItems.Add(1, mnuStop = new MenuItem("Stop", new System.EventHandler(mnuStop_Click)));<br />
mnuParentMenu.MenuItems.Add(2, mnuProperties = new MenuItem("Properties", new System.EventHandler(mnuProperties_Click)));<br />
<br />
mnuChildMenu.MenuItems.Add(0, mnuPropertiesC = new MenuItem("Properties", new System.EventHandler(mnuPropertiesC_Click)));<br />
<br />
node = new TreeNode("Credit Files");<br />
node.Tag = "ParentNodeMenu";<br />
node.ContextMenu = mnuParentMenu;<br />
treeView1.Nodes.Add(node);<br />
node = new TreeNode("VIO Copy Process");<br />
node.Tag = "ChildNodeMenu";<br />
node.ContextMenu = mnuChildMenu;<br />
treeView1.Nodes[0].Nodes.Add(node);<br />
<br />
node = new TreeNode("Human Resources");<br />
node.Tag = "ParentNodeMenu";<br />
node.ContextMenu = mnuParentMenu;<br />
treeView1.Nodes.Add(node);<br />
<br />
node = new TreeNode("Secondary Batch Update Process");<br />
node.Tag = "ChildNodeMenu";<br />
node.ContextMenu = mnuChildMenu;<br />
treeView1.Nodes[1].Nodes.Add(node);<br />
<br />
node = new TreeNode("TimeDeposits");<br />
node.Tag = "ParentNodeMenu";<br />
node.ContextMenu = mnuParentMenu;<br />
treeView1.Nodes.Add(node);<br />
<br />
node = new TreeNode("PurgeProcess");<br />
node.Tag = "ChildNodeMenu";<br />
node.ContextMenu = mnuChildMenu;<br />
treeView1.Nodes[2].Nodes.Add(node);<br />
<br />
node = new TreeNode("SecondaryBatchUpdateProcess");<br />
node.Tag = "ChildNodeMenu";<br />
node.ContextMenu = mnuChildMenu;<br />
treeView1.Nodes[2].Nodes.Add(node);<br />
splitContainer1.Visible = false;<br />
mnuStop.Enabled = false;<br />
<br />
}<br />
protected void mnuStart_Click(object sender, System.EventArgs e)<br />
{<br />
mnuStart.Enabled = false;<br />
mnuStop.Enabled = true; <br />
}<br />
protected void mnuStop_Click(object sender, System.EventArgs e)<br />
{<br />
mnuStop.Enabled = false;<br />
mnuStart.Enabled = true;<br />
}<br />
protected void mnuProperties_Click(object sender, System.EventArgs e)<br />
{<br />
splitContainer1.Visible = true;<br />
splitContainer1.Panel1Collapsed = false;<br />
splitContainer1.Panel2Collapsed = true;<br />
<br />
}<br />
protected void mnuPropertiesC_Click(object sender, System.EventArgs e)<br />
{<br />
splitContainer1.Visible = true;<br />
splitContainer1.Panel1Collapsed = true;<br />
splitContainer1.Panel2Collapsed = false;<br />
}<br />
private void treeView1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)<br />
{<br />
if (e.Button == MouseButtons.Right)<br />
{<br />
<br />
Point p = new Point(e.X, e.Y);<br />
<br />
TreeNode node = treeView1.GetNodeAt(p);<br />
if (node != null)<br />
{<br />
m_OldSelectNode = treeView1.SelectedNode;<br />
treeView1.SelectedNode = node;<br />
<br />
switch (Convert.ToString(node.Tag))<br />
{<br />
case "ParentNodeMenu":<br />
mnuParentMenu.Show(treeView1, p);<br />
break;<br />
case "ChildNodeMenu":<br />
mnuChildMenu.Show(treeView1, p);<br />
break;<br />
}<br />
<br />
treeView1.SelectedNode = m_OldSelectNode;<br />
m_OldSelectNode = null;<br />
if (node.Text.Equals("Credit Files"))<br />
{<br />
label1.Text = "Weekly Processes";<br />
}<br />
else if (node.Text.Equals("Human Resources"))<br />
{<br />
label1.Text = "Daily Process";<br />
}<br />
}<br />
}<br />
}<br />
<br />
}
each child node has a different set of properties which have to be set...i presume that for each child node we need a different panel.
also u have mentioned about some UserControls in one panel....i did not get that. Can u plz throw some more light on it?
waiting for your reply...
Sonu
|
|
|
|
|
Sonu.T wrote: about some UserControls in one panel
You could have separate UserControls instead of separate panels (Right click on Project in Solution Explorer -> Select Add -> UserControl). That way, each of your "panels" will be separate entities at design time. If you put everything in panels directly, then the main form holding all the panels would be congested with controls from different panels (when designing the UI from Visual Studio).
So you could have one panel to the right of the splitter and UserControl derived class for each of your screens. You could then load the appropriate control depending on the node selected in the tree. Something like
TreeNode selectedNode = ...;
switch(selectedNode.Text)
{
case "Weekly Processes";
panel.Controls.Clear();
panel.Controls.Add(weeklyProcessesControl);
break;
...
}
where panel is the System.Windows.Forms.Panel to the right of the splitter and weeklyProcessesControl is the usercontrol.
|
|
|
|
|
can I declare a variable, set it to a name of a form
then show it.
string a = "frm1";
form f = new a
f.show
help me
|
|
|
|
|
i don't know the exact solution but i use
if( a == "frm1")
{
form f = new a
f.show
}
|
|
|
|
|
Why do you want to do something like this? If all you want is to set the name of form, you could as well do
Form f = new YourForm();
f.Name = "frm1";
f.Show();
If frm1 is the name of the System.Windows.Forms.Form derived type and you want to instantiate it dynamically, you can do something like
string formTypeName = "frm1";
Type formType = Type.GetType(formTypeName);
Form f = (Form)Activator.CreateInstance(formType);
f.Show();
|
|
|
|
|
I have 2 List: customer list, supplier list
I have designed frmCus for customer list
I have designed frmSup for suppler list
I have a textbox: txta
I have a button : but1
When I click but1, if txta = "frmCus" then frmCus.show
else if txta = "frmSup" then frmSup.show
Can you help me ?
Thanks
|
|
|
|
|
When handling the button click, do you already have instances of frmCus and frmSup? If you do, you can simply do
Form form = null;
if (txta.Text == "frmCus")
form = frmCus;
else if (txta.Text = "frmSup")
form = frmSup;
form.Show();
If not, you'd have to resort to using reflection to create instances of frmCus and frmSup, using Activator.CreateInstance .
Form form = null;
if (txta.Text == "frmCus" || txta.Text = "frmSup")
form = (Form)Activator.CreateInstance(null, txta.Text);
form.Show();
This would create instances of frmCus and frmSup everytime you click the button, which may or may not be what you want. If you want to avoid creating instances everytime, you can have member variables in the class to refer to the instances created and then check for null before creating the instance.
|
|
|
|
|
Hi
I have problem with this code.
when a soloution have a more than project its not work
this code works only for main project. and for another project the value of formType is null.
please help me.
|
|
|
|
|
i create a class and generated random numbers using
texture = TextureStorageComposer.Objects[random.Next(0, 4)];
and then create 10 instances of that class
now the wired thing is that it gives same value to each instance when i run it
it gives different values when i step through it
i think this is because random is a time based function and all this processing is happening in less than 1ms (so all instances have same time for computer)
can you please help me in workaround
|
|
|
|
|
Are you creating 10 instances of System.Random or are you reusing the same instance and calling Next ? You should be getting repeated numbers only if you create multiple instances of the class very quickly. Did you try creating a single instance and repeatedly calling Next instead?
Alternatively, you could try using the RandomNumberGenerator[^] class.
|
|
|
|
|
Hi,
Im just wondering, how do you write the equals operator in C#.
Im slightly confused about the syntax.
For example in C++ for a vector :
<br />
class vector{<br />
private:<br />
float m_x;<br />
float m_y;<br />
float m_z;<br />
<br />
public:<br />
vector(x,y,z): m_x(x),m_y(y),m_z(z);<br />
vector(): m_x(0),m_y(0),m_z(0);<br />
~vector();<br />
<br />
bool operator==(Vector v)<br />
{<br />
if (this == v)<br />
return true;<br />
else<br />
return (m_x == v.m_x && v.m_y && v.m_z);<br />
}<br />
}<br />
I know its got something to do the Equals Function and Reference Equals Method. How do you test to see if its the same instance?
Many Thanks in advance
Tom
|
|
|
|
|
|
Thanks Nick,
Much Appreciated.
Its just that in C++ you would use the this statement and check against the type on the right.
I was just wondering if ReferenceEquals and Equals use the same kind of technique deep down in the CLR thats all.
But as for implementing it, you've hit the nail on the head.
Many Thanks
|
|
|
|
|
|
hi
it is my Code :
DataTable dt = new DataTable();foreach (DataGridViewRow _gridViewRow in dataGridView1.Rows)
{
if (_gridViewRow.Cells[0].Value != null && _gridViewRow.Cells[0].Value.ToString() == "True")
dt.ImportRow(ds_zamin1.Khaneh_1.Rows[_gridViewRow.Index]);
}
this.dataGridView1.DataSource = dt; // dt is global viriable
but when i execute this method,nothing occured,only myDatagridView show some blank row(s).
how to solve problem ?
|
|
|
|
|
Is there any way, when implementing a lock, that an incoming thread can force its own priority over the ones currently queued?
i.e. i've got 10 threads waiting to add items to a stack, and a thread that copies, empties and leaves the lock to process the copied items.
I don't want to wait N milliseconds for the items to be added to the stack as the processing thread is a priority, so i want the processing thread to jump to the front of the lock queue.
Is this possible? And how could i do it?
Cheers guys
Tristan Rhodes
|
|
|
|
|
Interesting quesiton. I don't believe setting the thread priority has anything to do with the acceesing the lock, I thought it was a FIFO construct. Never really thought about type of situation though.
only two letters away from being an asset
|
|
|
|
|
|
|
AFAIK they removed the original form border and created custom stuff for their form
|
|
|
|
|
Yep, but HOW...cause since the design mode I can't do it, the form properties don't allow me to do this things.
|
|
|
|
|
Set FormBorderStyle to none and draw the window yourself. Search for overriding WndProc and handling NC_HITTEST to make Window handle resizing/moving on a self-drawn form.
|
|
|
|
|
Hi,
Please help me …. I got a weird problem. I finished my project, everything was working fine. Recently my Win XP was updated by automatic update and I am not sure if my problem is related to this new update or not.
My problem:
In my win application, I have some MDI windows. Now, when I was running my application, I found that, some MDI Children is not being loaded, and 1 or 2 MDI children are being loaded. I could not understand why! So In my Visual Studio 2005 Professional, I clicked the Forms which were not being loaded. And I discovered that, I can’t open those windows anymore in the design mode. Nor even I can’t open them in the Code mode. Very frustrating! And Strange that, Some times when I tried to view the window in Design mode (VS 2005 Professional) instead of showing my Window Design, I used to get an Error Screen, some message was like “ License Manager …locked.. canot change the lock status….” Etc…etc…. I have no idea, from where this License Manager come….. Can you please help me..
Thanks and regards//…
|
|
|
|
|