|
Don't put this code in the button click event. Instead, create a function that takes a TreeNodeCollection as a parameter. This function will enumerate the Nodes in this collection and do your txtNote.Text work, just like you already have. At the same time, you can check each Node to see if it has any children (currentNode.Nodes.Count > 0). If it has children, then the function can call itself, recursively, with a reference to the current node's Nodes collection.
Private Sub Button1_Click(...)
ProcessNodesList( TreeView1.Nodes )
End Sub
.
. ' Warning! Untested code ahead!
.
Private Sub ProcessNodesList(ByRef nodeList As TreeNodeCollection)
Dim currentNode As TreeNode
For Each currentNode In nodeList
If currentNode.Checked = True Then
txtNote.Text += currentNode.Tag & " "
End If
If currentNode.Nodes.Count > 0 Then
ProcessNodesList( currentNode.Nodes )
End If
Next
End Sub
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Actually was just testing a solution that now works, but going to try to understand the recursive thing. Here is what I have for now that works for the first child. Recursive sounds like less code and better performance, but I am still new to some of this.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
Dim node As TreeNode
For Each node In TreeView1.Nodes
If node.Checked = True Then
txtNote.Text = txtNote.Text & node.Tag & vbCrLf
Dim child1 As TreeNode
For Each child1 In node.Nodes
If child1.Checked = True Then
txtNote.Text = txtNote.Text & child1.Tag & vbCrLf
End If
Next child1
End If
Next node
Addition.................
I tried your code and it works great without having to specify how many levels are present. I may have to use some sort of combination of yours adnd mine, because the first level needs to have a little different formatting like 2 vbcrlf after each of these nodes.
Thanks again for the help
End Sub
I assume the recursive function is better?
Thnks for the help
Marc
|
|
|
|
|
Is there any easy way to just have your function skip the first two levels? I would like to call the function only for the 2nd or 3rd Children and not the root or 1st child. This way I can ensure the formatting I need for the forst two levels. For instance I want one vbcrlf to follow the root, and one to precede and two to follow the first child so the resulting text would look like:
root
Child1
Child2 Child2 Child2
Child1
using the function will format ALL nodes the same. Any suggestions?
Thanks again for the help
Marc
|
|
|
|
|
Then add a second parameter to the function, telling it the level that it's on. Then modify the code that performs the formatting
Private Sub Button1_Click(...)
' Passing in 0 denotes the root of the tree.
' 1 would represent the 1st level of children, or children of the root.
ProcessNodesList( TreeView1.Nodes, 0 )
End Sub
.
. ' Warning! Untested code ahead!
.
Private Sub ProcessNodesList(ByRef nodeList As TreeNodeCollection, ByVal level As Integer)
Dim currentNode As TreeNode
For Each currentNode In nodeList
If currentNode.Checked = True Then
Select Case level
Case 0
' Put whatever formatting you want for level 0
Case 1
' Put whatever formatting you want for level 1
Case 2 To 3
' Put whatever formatting you want for levels 2 and 3
Case 4
' I hop eyou get the idea by now...
End Select
End If
If currentNode.Nodes.Count > 0 Then
' There are children present. Call myself with the new set
' of Nodes and tell myself that this is the next level down
ProcessNodesList( currentNode.Nodes, level + 1 )
End If
Next
End Sub
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thank you very much. Your suggestion worked perfectly.
Thanks again.
Marc
|
|
|
|
|
I am creating a custom control in VB.NET that inherits from System.Windows.Froms.ComboBox.
I am doing this so I can draw over the combo box to change it's appearance. To do the drawing I am overriding WndProc and capture the WM_PAINT message.
I can draw the background with no problems, but the problem is with the selected text, as the base class draws an edit box on top for this. When I want to set the enable property to false, the text and background is always grey. I need to be able to change the colour of this when disabled.
My other approach to this is to set a back color and not use the enabled property, but can't seem to override the OnClick event and cancel the event if another property is set to disable the control.
Any advice on this matter would be greatly appreciated.
Thanks
J
|
|
|
|
|
I would suggest you go to this project and use it. It is a great combobox and is easy to work with. I also think it will let you do all of the things you are asking about.
http://www.codeproject.com/vb/net/MultiColumnFlatCombo.asp
It also has a 3D setting so don't let the title fool you.
|
|
|
|
|
Hi!
How can I make buttoncolumns in windows application datagrid?
harald
|
|
|
|
|
hi harald,
have a look at this article on msdn. it should get you up to speed on how to place just about anything you might need in a datagrid column.
-jim
|
|
|
|
|
I have produced a grid from 2 tables that has been formated and displays about 100 rows of information (Each row has 30 cols). I would like to be able to print the grid. Has anyone any ideas how to do this or to point me in the right direction.
Thanks in advance.
Peter
|
|
|
|
|
This[^] little example on MSDN might get you started.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Mny tks for the help - will try it.
|
|
|
|
|
Try this
Dim ActivePageNumber As Short = 1<br />
Dim pageCount As Short = 0<br />
Dim ItemCountOnPerPage As Integer = 30<br />
Dim dtSource As DataTable<br />
Dim index As Short<br />
Private Sub btnPrintDataGrid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintDataGrid.Click<br />
ActivePageNumber = 1<br />
pageCount = Math.Ceiling(dtSource.Rows.Count / ItemCountOnPerPage)<br />
PrintDocument1.Print()<br />
End Sub<br />
<br />
<br />
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage<br />
If Not ActivePageNumber > pageCount Then<br />
PrintDataTable(e.Graphics)<br />
ActivePageNumber += 1<br />
e.HasMorePages = True<br />
Else<br />
e.HasMorePages = False<br />
End If<br />
End Sub<br />
<br />
Public Sub PrintDataTable(ByVal e As Graphics)<br />
Dim x, y As Short<br />
Dim fArial As New Font("Arial", 8)<br />
x = 20<br />
y = 20<br />
Dim cci As Short = index<br />
Do While (cci <> ItemCountOnPerPage Or index <> dtSource.Rows.Count - 1)<br />
For columnIndex As Short = 0 To dtSource.Columns.Count - 1<br />
e.DrawString(dtSource.Rows(index)(columnIndex), fArial, New SolidBrush(Color.Black), x, y)<br />
x += 30 ' set this to column width<br />
Next<br />
y += fArial.Height<br />
cci += 1<br />
index += 1<br />
Loop<br />
End Sub
|
|
|
|
|
Mny tks - will try it out.
Peter
|
|
|
|
|
A rather tricky question: Is is possible to design a program to lay on top of two other programs in order to be able to control the audio from these 2 programs. I want to be able to mute the first programs audio so that the other can use the speaker, and the unmute so that the first program uses the speaker. Does anyone know if this is possible? If so, could someone provide me with sample code for VB.net?
Best regards
Mikkel
|
|
|
|
|
No, you can't, for various reasons that depends entirely on the resources and devices your applications are using. You can't control the audio output of those two applications.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi guys
here's my matter:
I want to select (highlight) a word in any application and when I click the right mouse button, I dont want the popup menu to renders, I want to set my own function here, how can I prevent the menu, I saw lots of code on how to disable it in a text box, but here, I want it in general, whenever the right button is clicked...
Anyone can help please.
|
|
|
|
|
You want to disable context menus system-wide? And replace them with your own incarnation of whatever? What are you planning on attempting?
BTW: IMHO it's a very bad idea to do this.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
i am trying to add key in the app.config file programitically i am able to read the key through this ReadConfigFile.AppSettings("ConnectionString"), but if i want to add a key during runtime how can i do that.
|
|
|
|
|
Since the app.config file is an XML file, I would probably start with XmlTextReader to load the file and use whatever XML document methods you need to accomplish your goal.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have written a class in C++ and would like to define it as a variable data type in VB. How should I go about it??
|
|
|
|
|
Chances are you're going to do a little rewriting of your class. But your question would be better handled in the Visual C++ forum as I THINK(!) your going to be exposing it to COM so VB can see and use it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I am attempting to write a program that will list the running processes on a computer. I currently have a listView box that stores the running processis as items in the ListView. The ListView must update every so often (2 secons or so).
But when it updates it must check to see if a process is already contained in the list. For example there are usually four or so processes with the name svchot.exe, so we must make sure that we also check the PID (a subitem for each item that stores the "Process ID").
My problem is that when I attempt to check if an item is in the listView, it is not found. Here is the coded snipet in question.
'Takes three parameters: lvw is the ListView that contains all of the items,
'item_title is the name of the item we want to add (process name),
'subitem_titles() is an array of strings containing the subitems (PID, CPU time...) Private Sub ListViewMakeRow(ByVal lvw As ListView, ByVal ProcessName As String,_ ByVal ParamArray subitem_titles() As String)
'Temporary ListViewItem used to create a lvw
Dim ListItemTemp As New ListViewItem(ProcessName)
'check to see if our TempListItem is found in lvw
'At least that is what it is supposed to do.
If Not (lvw.Items.Contains(TempListItem)) Then
Dim new_item As ListViewItem = lvw.Items.Add(ProcessName)
For i As Integer = subitem_titles.GetLowerBound(0) To _
subitem_titles.GetUpperBound(0)
new_item.SubItems.Add(subitem_titles(i))
Next i
Else
End If
End Sub
At the moment I am only trying to see if I can check to see if the item is already in the ListView. Later on I will add more checks to see if it is a different process.
Currently the process will continue to add more items to the list even if the item is found in the list. I am not able to debug it to see which items are already in the list and to see if it is making the correct decision. However I know that it does not work because every half a second or so another item with the same name is added to the list (every second a process named “explorer.exe” is added… and so on for each process that runs.
So the question is can anyone point me to a good tutorial on the:
ListView.ListViewItemCollection.Contains
or to some other way of checking the ListView. I have looked at microsofts inof for the ListView class
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformslistviewitemlistviewsubitemclasstopic.asp
however their example does not use the Contains method.
I will attempt to use GetIndexOf. However I am not sure how that would work if there are multiple items with the same name.
Thanks in Advance
Donald Carlson, Jr.
|
|
|
|
|
Unfortunately it is a bit ineficent and lacks the update capabilities, however it does properly check to see if an item with the same name exists and also checks to see if an item with the same subitem exists (assuming there are more then one item with the same name). IF you have any improvements or other ideas pleas feel free to post them.
Private Sub ListViewMakeRow(ByVal lvw As ListView, ByVal ProcessName As String, ByVal ParamArray subitem_titles() As String)
'Creates a temporary listViewItem
Dim CurrentListItem As ListViewItem
'check to see if our TempListItem is found in lvw
If (lvw.Items.Count = 0) Then
'there are no entries in the list (list is empty)
Dim new_item As ListViewItem = lvw.Items.Add(ProcessName)
For i As Integer = subitem_titles.GetLowerBound(0) To _
subitem_titles.GetUpperBound(0)
new_item.SubItems.Add(subitem_titles(i))
Next i
Else
'Well apparently the list is not empty
Dim dataListEnumerator As IEnumerator = lvw.Items.GetEnumerator()
Dim containsItem As Boolean = False
Dim PID As String
'check all entries in the list
While (dataListEnumerator.MoveNext())
CurrentListItem = CType(dataListEnumerator.Current, ListViewItem)
' Display the current DataListItem onto the label.
If (ProcessName = CurrentListItem.Text) Then
containsItem = True
'Stores the PID for later checking if needed
PID = PID & " " & CurrentListItem.SubItems.Item(1).Text
End If
End While
If (containsItem = False) Then
'this process is not found in the list
Dim new_item As ListViewItem = lvw.Items.Add(ProcessName)
For i As Integer = subitem_titles.GetLowerBound(0) To _
subitem_titles.GetUpperBound(0)
new_item.SubItems.Add(subitem_titles(i))
Next i
Label2.Text = "sweet unnion rings"
ElseIf (PID.IndexOf(subitem_titles(0)) = -1) Then
'this specific process with this specific PID is not found
'Assumes that contansItem is true
Dim new_item As ListViewItem = lvw.Items.Add(ProcessName)
For i As Integer = subitem_titles.GetLowerBound(0) To _
subitem_titles.GetUpperBound(0)
new_item.SubItems.Add(subitem_titles(i))
Next i
End If
End If
End Sub
Donald Carlson, Jr.
|
|
|
|
|
Hi all
I am trying to convert a html page (home.htm) to an asp page (home.aspx). Please can anyone show me how to work this out?
Thanks very much for help!
|
|
|
|