|
Go add a new TreeNode at the same level as a given TreeNode you will need to look at the current TreeNode's parent and add your new node to the parents Nodes collection using the Insert method of the TreeNodeCollection.
A rough example (not tested):
.
.
.
int currentIndex = CurrentTreeNode.Parent.Nodes.IndexOf(CurrentTreeNode);
.
.
.
CurrentTreeNode.Parent.Nodes.Insert(NewNode,currentIndex);
.
.
.
CurrentTreeNode.Parent.Nodes.Insert(NewNode,currentIndex+1);
.
.
.
Note that you should check that the current node isn't the root (parent == null).
To add a child you simply add a new node to the current node using CurrentTreeNode.Add(NewNode)
To disable the menu items you might want to do it on the context menus Popup event.
|
|
|
|
|
How can I set the currentTreeNode equal to Selected Node.
I want to add before and after the selected node.
Thank you.
|
|
|
|
|
You need to hook in to the AfterSelect event and then test the value of e.Node.Level to determine what level in the tree control the selected node is located. Based on this value you can enable/disable different menu items. To do this with mouse clicks, you need to hook in to the NodeMouseClick event. You can test using something like e.Node.IsSelected && e.Button == MouseButtons.Right
In your event handlers, you will need to use the value of e.Node to determine which node you need to interact with to add the new TreeNode object.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Hi
I can develop a project in multilanguage in C# but i am unable to convert it in VB.net. Any one ready for assistance...................
Regards
Syed Shahid Hussain
|
|
|
|
|
Hi,
I know that to convert an int to a string you use:
myInt.toString();
But, I want to convert a string to int, what is the function for this?
Thanks.
|
|
|
|
|
In .NET 2.0 use Int32.TryParse , otherwise Int32.Parse .
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thanks mate, a great help
|
|
|
|
|
There is also a method like
Convert(variable,CType)
Good Luck
Syed Shahid Hussain
|
|
|
|
|
Just FYI, there is also a method called Convert.ToInt32(). Either method will work fine.
|
|
|
|
|
I've created a control that has a simple label on it and a progress bar. When a certain event happens i create a new instance of the control and add it to my parent control. Once the event is finnished i dispose of the control.
My problem is that the control is never displayed. I know its being created since i've added trace's and can see that its checking to see if it needs to update the progress bar.
When i call the progress bar, i check to see if it needs to be invoked and then do the below code:
initControl = new InitControl();<br />
this.Controls.Add(initControl);<br />
<br />
int posX = ((this.Width / 2) - (initControl.Width / 2));<br />
int posY = ((this.Height / 2) - (initControl.Height / 2));<br />
initControl.SetBounds(posX, posY, 100, 100);
The question is, What am i missing so the control isnt showed?
|
|
|
|
|
gareth111 wrote: Once the event is finnished i dispose of the control. A control that has been disposed is not going to display.
led mike
|
|
|
|
|
There are mainly 2 to 3 points you need to take care of:
1.) You are adding to this.Controls , so hopefully there should be no other control present at the same Location within this.Controls array.
2.) The InitControl is the topmost control within the this.Controls list.
3.) The InitControl's 'Visible' property is set to TRUE.
Regards,
Vin...
There are two types of fools in this world: One who give advice and the others who do not take it...
|
|
|
|
|
led mike:
I dont dispose of it until im finnished with it, i dont just create it and then dispose of it instantly.
vinSharp:
Its visiability is set to true, but im unsure what you mean by 1 and 2.
|
|
|
|
|
gareth111,
By points 1 and 2 I meant the following:
Suppose you add InitControl at Location (10,10) within the this.Controls
and elsewhere you add another opaque control whose span overlaps the InitControl, then also it would make your control invisible.
To do a double check on that, add the following line after initControl.SetBounds(...)
Add the line: initControl.BringToFront()
Check whether this works for you...
There are two types of fools in this world: One who give advice and the others who do not take it...
|
|
|
|
|
|
i want to integrate a sentinel hardware device with one of my applications that icreated, so i wanted to know if C# is able to check for hardwares that are plugged in on your machine, so i would love for anyone to tell me how to do this or send me a link of what to read up on to do this
kenny edmond
|
|
|
|
|
C# and the .NET framework don't do this. You can use P/Invoke[^] to call into the Win32 API all you like though, so if it's possible there, it's possible through C#.
|
|
|
|
|
I have a datagrid bound to an ArrayList
Is it possible to search this datagrid by filtering on text into a text box
for a specific column?
Any advice is very much welcome
|
|
|
|
|
Yes I think it is. I expect you'll have to define IComparable on the class you use to represent a row of the grid, so that you can do a search on the collection. I've not tried it but I vaguely remember seeing an online article somewhere which did this.
Kevin
|
|
|
|
|
Do you mean a DataTable?
I'm going to guess that you do, or that you have a datatable feeding both the DG and the Arraylist.
Anyways, you can adjust the datatable.defaultview.filter property with SQL-like filter parameters.
|
|
|
|
|
No I don't have a datatable..
I have an object filled by a stored procedure.
The datagrid is filled by calling the fetch function on the class
Thanks
|
|
|
|
|
OK, fill a datatable with the fetch function and then make that the datagrid's datasource.
|
|
|
|
|
yes that is what I have done..
I want to be able to now enter search criteria into a text box and filter the grid
|
|
|
|
|
OK. On some event (button click or textbox changed), set the DataTable.DefaultView.RowFilter = " Field like " + TextBox.Text
|
|
|
|
|
I'd really love to but I'm not using a DataTable
|
|
|
|