树视图复选框已签入数据集 [英] treeview check box checked into dataset

查看:132
本文介绍了树视图复选框已签入数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,请告知如何获取选中的复选框treeview vb.net代码以添加到数据集后数据库(ado.net)

Hi, Please advise how to get the checked checkbox treeview vb.net code to add to the dataset After database (ado.net)

推荐答案

Private Sub frmUserLevel_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

      btnSave.Enabled = False
      btnCancel.Enabled = False
      Me.Text = "فرم تعیین مجوزسال مالی"


      'Creates 2 DataAdapters
      Dim daTbl_Yaers As New OleDbDataAdapter("SELECT * FROM Tbl_Yaers", con)
      Dim daTbl_UserName As New OleDbDataAdapter("SELECT * FROM Tbl_UserName", con)
      'Creates and fills the dataset with the 2 DataAdapters
      Dim ds As New DataSet
      daTbl_Yaers.Fill(ds, "Tbl_Yaers")
      daTbl_UserName.Fill(ds, "Tbl_UserName")

      With TreeView1
          'prevents the control from painting until the EndUpdate method is called
          .BeginUpdate()
          'Clears/Deletes all nodes that currently exist
          .Nodes.Clear()
          'Sets the ImageList


          '.ImageList = ImageList1


          'Loop through all rows of the Tbl_UserName table
          For Each drUserName As DataRow In ds.Tables("Tbl_UserName").Rows
              'Adds the Category as a root node
              'Dim nodParent As TreeNode
              nodParent = TreeView1.Nodes.Add(drUserName.Item("strUserName").ToString & "  " & drUserName.Item("Persian_Name").ToString)

              'nodParent.ImageIndex = 1
              'Loops through the Acc_Years related to the Category
              For Each drYaers As DataRow In ds.Tables("Tbl_Yaers").Rows
                  'Adds the Product as a child of the Category
                  'Dim nodChild As TreeNode
                  nodChild = nodParent.Nodes.Add(drYaers.Item("YaerField").ToString)

                  If nodChild.Text.ToUpper.IndexOf("Y") >= 0 Then
                      nodChild.BackColor = Color.Gray
                  End If
                  nodChild.ImageIndex = 0

              Next drYaers

          Next drUserName
          ''Expands all nodes
          '.ExpandAll()



          'Enables the redrawing of the tree view
          .EndUpdate()
          'Ensures that the first node is visible
          .Nodes(0).EnsureVisible()
      End With

  Private Sub TreeView1_Click(sender As Object, e As System.EventArgs) Handles TreeView1.Click
        'con.Open()
        Dim cmd As New OleDbCommand
        Dim da As New OleDbDataAdapter("SELECT * FROM Acc_Years", con)

        For I As Integer = 0 To TreeView1.Nodes.Count - 1



            If (TreeView1.Nodes(I).Checked) Then


                Dim daAcc_Years As New OleDbDataAdapter("SELECT * FROM Acc_Years", con)
                Dim ds As New DataSet
                daAcc_Years.Fill(ds, "Acc_Years")
                Dim dr As DataRow
                dr = ds.Tables("Acc_Years").NewRow
                dr.Item("strUserName") = nodParent.Text
                dr.Item("AccYear") = nodChild.Text
                ds.Tables("Acc_Years").Rows.Add(dr)
                Dim cd As OleDbCommandBuilder
                cd = New OleDbCommandBuilder(daAcc_Years)
                daAcc_Years = cd.DataAdapter
                daAcc_Years.Update(ds, "Acc_Years")
                MsgBox("insert data")
           

            End If
        Next
    End Sub

   


  End Sub


这篇关于树视图复选框已签入数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆