11 Replies - 438 Views - Last Post: 20 January 2018 - 02:18 PM Rate Topic: -----

#1 dendenden  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 09-January 18

Treeview checkboxes using

Posted 15 January 2018 - 06:35 AM

hello friends, I want to make a program that send a checked treeview boxes to new form but only checked one is that possible? If it could I need any source to learn Thank you.
Is This A Good Question/Topic? 0
  • +

Replies To: Treeview checkboxes using

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13765
  • View blog
  • Posts: 54,945
  • Joined: 12-June 08

Re: Treeview checkboxes using

Posted 15 January 2018 - 07:45 AM

I would imagine you could cycle through your data source backing your tree and see what is 'checked' or not.
Was This Post Helpful? 1
  • +
  • -

#3 IronRazer  Icon User is offline

  • Custom Control Freak
  • member icon

Reputation: 1470
  • View blog
  • Posts: 3,725
  • Joined: 01-February 13

Re: Treeview checkboxes using

Posted 15 January 2018 - 11:53 AM

Quote

I want to make a program that send a checked treeview boxes to new form but only checked one is that possible?

Well, yes that is possible. However, how you do it will all depend on if you want just checked root nodes or all checked nodes to be sent. It will also depend on when you want them sent to the other form.

About all we can suggest with the information you gave is to look at the TreeView.CheckedNodes Property documents. You can look at the Passing Data Between Forms tutorial that is right here on DIC too. You will need to decide which method fits your needs.
Was This Post Helpful? 2
  • +
  • -

#4 andrewsw  Icon User is online

  • blow up my boots
  • member icon

Reputation: 6500
  • View blog
  • Posts: 26,288
  • Joined: 12-December 12

Re: Treeview checkboxes using

Posted 15 January 2018 - 02:20 PM

Another consideration is what the checked nodes represent. There could be a data model involved and the checked items would, presumably, represent a current state. It is this state that would need to be preserved, or transferred, between forms, not necessarily a collection of UI selections.
Was This Post Helpful? 1
  • +
  • -

#5 dendenden  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 09-January 18

Re: Treeview checkboxes using

Posted 16 January 2018 - 01:38 AM

yes you right I couldnt express my problem, here I have excel document like this(that is so small according to orginal one).

Posted Image

now user will choose pole types, from here

Posted Image

then in form 2 program should total price and weight of choosed ones.
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • blow up my boots
  • member icon

Reputation: 6500
  • View blog
  • Posts: 26,288
  • Joined: 12-December 12

Re: Treeview checkboxes using

Posted 16 January 2018 - 03:44 AM

You should then have a model to represent electric poles. That is, a class structure. You cannot bind directly to a TreeView but you can use events of the TreeView (click, check, whatever it has available) to alter the current state.

So you might have a List<ElectricPole> and checking or unchecking a box could add or remove items from this collection. Then it is this model/collection that needs to be shared, or passed between, the forms, as detailed in the tutorial.



Anyway, it is up to you. If, as a beginner, you want to start just by passing the checked nodes to the other form, then my tutorial describes the various ways that you could do this. However, even with this basic approach, you'll still need a data structure in order to retrieve the prices and weights.
Was This Post Helpful? 1
  • +
  • -

#7 dendenden  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 09-January 18

Re: Treeview checkboxes using

Posted 16 January 2018 - 04:23 AM

thank you friend, I am going to read tutorial.
Was This Post Helpful? 0
  • +
  • -

#8 dendenden  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 09-January 18

Re: Treeview checkboxes using

Posted 19 January 2018 - 12:04 AM

hey, it is me again. I still cant complete that. now I have pole class which has a name,price and weight variables and have object like object1; name,price,weight take from excel sheet.
but I still cant attach these objects to treeview. I read forum but cant understand
Was This Post Helpful? 0
  • +
  • -

#9 dendenden  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 09-January 18

Re: Treeview checkboxes using

Posted 19 January 2018 - 12:17 AM

do you have any suggestion maybe I should use different tool instead of treeview
Was This Post Helpful? 0
  • +
  • -

#10 andrewsw  Icon User is online

  • blow up my boots
  • member icon

Reputation: 6500
  • View blog
  • Posts: 26,288
  • Joined: 12-December 12

Re: Treeview checkboxes using

Posted 19 January 2018 - 03:53 AM

As I mentioned, the TreeView is not directly bind-able to a data source. You would have to manually map, and populate, items of your model to TreeView nodes, and use events of the TV to alter the state; that is, to add and remove poles from a collection. (There is a simpler version of this, which is to use a single event, such as clicking a button, to adjust the state.)

There are many other controls that can be directly bound to a data source. DataGridView, CheckedListBox, TextBoxes, ComboBoxes, etc..



Based on the TreeView screenshot it does look like there is potentially a lot more to your data model than just the few poles/rows from the spreadsheet. It is, of course, up to you how detailed or simplified your model needs to be.
Was This Post Helpful? 1
  • +
  • -

#11 IronRazer  Icon User is offline

  • Custom Control Freak
  • member icon

Reputation: 1470
  • View blog
  • Posts: 3,725
  • Joined: 01-February 13

Re: Treeview checkboxes using

Posted 19 January 2018 - 09:43 AM

It is not clear to me if there is a 'Pole' class for each TreeNode or how it is suppose to work from your images but, maybe try assigning the 'Pole' classes, or some type of class to hold the info for each TreeNode, to their corresponding TreeNode's Tag property.

Then you can use the AfterCheck event of the TreeView to detect which TreeNode was just checked or un-checked. All you need to do then, is to add or remove the data from the 2nd form, or a collection that will be sent to the 2nd form.

Here is a small basic example just to give you the idea of what i am saying. You can test it in a new form project with one TreeView added to the form.
Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim RootNode1 As TreeNode = TreeView1.Nodes.Add("20FootPole2", "20 Foot Pole") 'adds a root node to the treeview

        Dim chldnode As TreeNode = RootNode1.Nodes.Add("A Type") 'adds a "Type A" child node to the root node
        chldnode.Tag = New PoleInfo("A", 20, 98.95) 'assign a new PoleInfo class with info about this node, to this node's Tag property

        chldnode = RootNode1.Nodes.Add("B Type") 'adds a "Type A" child node to the root node
        chldnode.Tag = New PoleInfo("B", 20, 104.38) 'assign a new PoleInfo class with info about this node, to this node's Tag property
    End Sub

    Private Sub TreeView1_AfterCheck(sender As Object, e As TreeViewEventArgs) Handles TreeView1.AfterCheck
        If e.Node.Level > 0 Then 'stops this code from executing if it was a root node that was checked/un-checked
            Dim pInfo As PoleInfo = CType(e.Node.Tag, PoleInfo) 'cast the checked/un-checked node's Tag property to a PoleInfo class so you can get it's info
            If e.Node.Checked Then
                'The TreeNode (e.Node) was checked, add it to the 'pole' items...
                MessageBox.Show(pInfo.PoleType & ",  " & pInfo.PoleHeight.ToString & ",  " & pInfo.PolePrice.ToString("C2"), "Checked...")
            Else
                'The TreeNode (e.Node) was un-checked, remove it from the 'pole' items...
                MessageBox.Show(pInfo.PoleType & ",  " & pInfo.PoleHeight.ToString & ",  " & pInfo.PolePrice.ToString("C2"), "Un-Checked...")
            End If
        End If
    End Sub
End Class

Public Class PoleInfo
    Public Property PoleType As String
    Public Property PoleHeight As Integer
    Public Property PolePrice As Double
    Public Sub New(pType As String, pHeight As Integer, pPrice As Double)
        PoleType = pType
        PoleHeight = pHeight
        PolePrice = pPrice
    End Sub
End Class

Was This Post Helpful? 1
  • +
  • -

#12 dendenden  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 09-January 18

Re: Treeview checkboxes using

Posted 20 January 2018 - 02:18 PM

Thank you guys, you realy help me. Actually I learn a lot from this site. Maybe you can suggest me any book for learn more about coding(vb.net).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1