|
I have a recursive query which fetches a heirachy for me. now i want to show that heirachy in a tree view.
The problem in showing it in a treeview is that it is adding only one child in the parent. If there child itself is a parent then a new node is created instead of adding it in the existing node.
like this
1->2
2->3
3->4
4->5
and i want something like this
1->2->3->4->5
Can anyone Help?
|
|
|
|
|
Post the code that populates the TreeView. You're not properly tracking which node your adding children too.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have solved it Here's the code:
Protected Function RecursiveQuery(ByVal ParentID As String)
Dim strSelect As String
strSelect = "select R.RE_Child,D.RE_entities_Name as Child from Relation_Detail R,Relation_Master D where R.RE_Child=D.Relation_Master_code and RE_Parent='" & ParentID & "'"
Dim con As SqlClient.SqlConnection = New SqlClient.SqlConnection("workstation id=localhost;packet size=4096;user id=sa;data source=localhost;persist security info=False;initial catalog=Test")
Dim sqcmdRecursive As SqlCommand = New SqlCommand(strSelect, con)
Dim strParentID As String
Dim strChildID As String
Dim sqrd As SqlDataReader
Dim tvCreate As TreeNode
Try
If con.State = ConnectionState.Closed Then
con.Open()
End If
sqrd = sqcmdRecursive.ExecuteReader
While sqrd.Read
arParent.Add(ParentID)
strChildID = sqrd.Item(0)
If ParentID.Equals("0") Then
ParentNode = New TreeNode(ParentID).Nodes.Add(sqrd.Item(1))
ParentNode.Tag = sqrd.Item(0)
PasteImages(ParentNode, sqrd.Item(0))
TreeView1.Nodes.Add(ParentNode)
ElseIf shFlag = 1 Then
ParentNode = New TreeNode(ParentID)
Dim NewNode As TreeNode
NewNode = New TreeNode(sqrd.Item(1))
NewNode.Tag = sqrd.Item(0)
PasteImages(newnode, sqrd.Item(0))
Add2Node(TreeView1.Nodes, ParentNode, NewNode)
Else
ParentNode = New TreeNode(ParentID)
Dim NewNode As TreeNode
NewNode = New TreeNode(sqrd.Item(1))
NewNode.Tag = sqrd.Item(0)
PasteImages(newnode, sqrd.Item(0))
Add2Node(TreeView1.Nodes, ParentNode, NewNode)
End If
RecursiveQuery(sqrd.Item(0))
End While
Catch ex As Exception
MsgBox(ex.ToString)
Finally
con.Close()
shFlag = 1
End Try
End Function
Private Function Add2Node(ByVal TestNode As TreeNodeCollection, ByVal findnode As TreeNode, ByVal newnode As TreeNode) As Boolean
Dim n As TreeNode
For Each n In TestNode
If n.Tag = findnode.Text Then
n.Nodes.Add(newnode)
Add2Node = True
Exit Function
End If
Add2Node(n.Nodes, findnode, newnode)
Next
End Function
|
|
|
|
|
I have solved the problem. Here's the code:
Protected Function RecursiveQuery(ByVal ParentID As String)
Dim strSelect As String
strSelect = "select R.RE_Child,D.RE_entities_Name as Child from Relation_Detail R,Relation_Master D where R.RE_Child=D.Relation_Master_code and RE_Parent='" & ParentID & "'"
Dim con As SqlClient.SqlConnection = New SqlClient.SqlConnection("workstation id=localhost;packet size=4096;user id=sa;data source=localhost;persist security info=False;initial catalog=Test")
Dim sqcmdRecursive As SqlCommand = New SqlCommand(strSelect, con)
Dim strParentID As String
Dim strChildID As String
Dim sqrd As SqlDataReader
Dim tvCreate As TreeNode
Try
If con.State = ConnectionState.Closed Then
con.Open()
End If
sqrd = sqcmdRecursive.ExecuteReader
While sqrd.Read
arParent.Add(ParentID)
strChildID = sqrd.Item(0)
If ParentID.Equals("0") Then
ParentNode = New TreeNode(ParentID).Nodes.Add(sqrd.Item(1))
ParentNode.Tag = sqrd.Item(0)
PasteImages(ParentNode, sqrd.Item(0))
TreeView1.Nodes.Add(ParentNode)
ElseIf shFlag = 1 Then
ParentNode = New TreeNode(ParentID)
Dim NewNode As TreeNode
NewNode = New TreeNode(sqrd.Item(1))
NewNode.Tag = sqrd.Item(0)
PasteImages(newnode, sqrd.Item(0))
Add2Node(TreeView1.Nodes, ParentNode, NewNode)
Else
ParentNode = New TreeNode(ParentID)
Dim NewNode As TreeNode
NewNode = New TreeNode(sqrd.Item(1))
NewNode.Tag = sqrd.Item(0)
PasteImages(newnode, sqrd.Item(0))
Add2Node(TreeView1.Nodes, ParentNode, NewNode)
End If
RecursiveQuery(sqrd.Item(0))
End While
Catch ex As Exception
MsgBox(ex.ToString)
Finally
con.Close()
shFlag = 1
End Try
End Function
Private Function Add2Node(ByVal TestNode As TreeNodeCollection, ByVal findnode As TreeNode, ByVal newnode As TreeNode) As Boolean
Dim n As TreeNode
For Each n In TestNode
If n.Tag = findnode.Text Then
n.Nodes.Add(newnode)
Add2Node = True
Exit Function
End If
Add2Node(n.Nodes, findnode, newnode)
Next
End Function
|
|
|
|
|
I have an existing form I created from vb studio and I am working on how to update and fill an access database from the text fields when the user clicks the submit button. Help please
|
|
|
|
|
This is such a common task, that I doubt you'd have any trouble searching google for articles on it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
VB6, VB.NET (1.0 or 2.0)?
In any case the official documentation on CD (or MSDN on-line) has plenty of examples and ready to use code about that.
|
|
|
|
|
I need code for creating a TCP/IP communication inside visual basic adding the Winsock control so that you acan chat on a port
|
|
|
|
|
Try searching this site or Google for code. It's amazing what you can find if you try.
...Steve
|
|
|
|
|
I am looking to implement a text editor functionality Using VB.NET in ASP.NET that allows for the following:
1. If any text or number is changed, it gets "striked Out" but never over written ever.
2. If anything is deleted, it gets striked out as well.
I can use RTF editor (example R.A.D editor from Telerik)to let user enter information for the first time. Next time when they change or deleted, I need to implement the strike out feature.
Any ideas, and suggestions will be greatly appreciated.
|
|
|
|
|
Basically want you want to do is, during postback, work out what has changed, and then send it back with a strikeout through the old document. So, the main thing you need is to write code to difference the document you sent to the user, and the document they submitted back.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I'm trying to decide the best way to setup my DataTables and DataAdapters.
Which way is the best way?
1. Use the DataAdapter wizard and have separate DataTables and DataAdapters for each form in the project.
2. Define public DataTables and DataAdapters in a module so that these objects are available to all forms.
Thanks for any input.
|
|
|
|
|
dptalt wrote:
Use the DataAdapter wizard and have separate DataTables and DataAdapters for each form in the project.
This way is crap. I take it this means you're not even implimenting a middle tier ?
dptalt wrote:
Define public DataTables and DataAdapters in a module so that these objects are available to all forms.
Yes, what should happen is that you have a seperate module that handles data access, and returns the required data to the middle tier. That way, your data layer is seperate from the rest of the app.
That Microsoft provides DataAdapters at all is a travesty, IMO. Assuming you're using a real database, you should write your database code as stored procedures, and your data layer should call those procs and return the result. Putting SQL generation in the hand of a wizard, and passing SQL statements like select and update to the data layer from the application layer is just crap, unless the apps your writing are just for fun, or at least will run on one machine with a local database. It's still not the right way to architect things tho.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Ok, Thanks for the advice.
I do think the DataAdapter wizards are great for the beginner.
Do you use DataAdapters in your middle tier? If not what do you use?
|
|
|
|
|
Got this web application that lets a user create a form which is written to an sql database. It contains various textboxes and dropdownlists etc. It creates the form no problem but when it comes to updating this form i do. First off the user searches for their form.
Once found they click update, which retrieves all the info stores this in a session and returns the appropriate text to the appropriate control eg. if conor was the name of the user in the database the application would set the text attribute of the username control to conor.
the user is able to modify these controls again and click on update. Here is the problem. once the update button is clicked no event take place so the updates are not being saved to the database.
If i get this sorted it's the end of my project so it will greatly appreciated if anyone can help me.
|
|
|
|
|
mcgannmcgann wrote:
Here is the problem. once the update button is clicked no event take place so the updates are not being saved to the database.
Is the button dynamically generated ? Have you defined an event for it ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Can someone teach me how can I begin writting one simple appliaction which can read barcodes...
Regards
|
|
|
|
|
In this website there are an example about barcodes and examples
Try this one:
“VBScan barcode software
by demm”
If you just want to input the values throw the scanner it work like a second keyboard, set focus to the location and scan.
|
|
|
|
|
Hi All,
using Vb.Net i want to connect to internet and send a mail programatically . can any body give me some guidelines?
regards
sumedha
|
|
|
|
|
Dim Message As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
Message.To = "<to-emailid>"
Message.From = "
|
|
|
|
|
ciacia wrote:
send a mail programatically
using the solution of the guy above
ciacia wrote:
i want to connect to internet
using HttpWebRequest/HttpWebResponse (I dont remember exactly the namespace)
<< >>
|
|
|
|
|
Ok, my situation is like this. I have two forms in my application (Form1 and Form2), and on each form, I have one button (button1). I put the following code in button1 for Form1.
"Dim frm2 as new Form2"
"frm2.show()"
and in Button1 of Form2
"Dim frm1 as new Form1"
"frm1.show()"
I noticed that if I clicked on these buttons a couple of times, multiple Form1 and Form2 gets created. Anyway to avoid this, like maybe when I click Form1 Button1, it closes the Form1 and opens Form2 and vice versa..?
|
|
|
|
|
icowa wrote:
when I click Form1 Button1, it closes the Form1 and opens Form2 and vice versa
I think u dont need to close form1 and open form2 and vice versa...
u can let 2 forms are opened concurrently.
below is just my suggestion:
- In each form, u have a variable (boolean), named as isActive to store the status of the other form (this will be initialized as false, that means form2 is not activating),
ie: when click form1 button1, the code should be as below:
"Dim frm2 as new Form2"
"if isActive then " //form2 is being actived
" frm2.active()"
"else " //form2 has not been showed yet
"isActive = true"
"frm2.show()"
and certainlly, before form2 is closed, u need to set isActive = false in form1
and do the same thing for form2
<< >>
|
|
|
|
|
I'm not sure if I got it correctly.....
if you want to have a single form1 and form2 then the solution is not to re-declare them inside the procedure but just once at the beginning of the code. Thay way you are going to recall always the same one without creating a new instance.
|
|
|
|
|
How do you go about doing that? Any help that you can offer will be greatly appreciated... Thanz
|
|
|
|