成都创新互联网站制作重庆分公司

vb.net中init,aspnet vb

vb.net treeview的递归代码看不懂啊~ 求高手解释~

'initTrvTree是用递归方法初始化TreeView控件的节点

在网站建设、成都网站制作过程中,需要针对客户的行业特点、产品特性、目标受众和市场情况进行定位分析,以确定网站的风格、色彩、版式、交互等方面的设计方向。成都创新互联公司还需要根据客户的需求进行功能模块的开发和设计,包括内容管理、前台展示、用户权限管理、数据统计和安全保护等功能。

Public Sub initTrvTree(ByRef nodes As TreeNodeCollection, _

ByVal strParentIndex As String, _

ByVal dvList As DataView)

Try

Dim tempNode As TreeNode

Dim currentId As String

'选出数据源中ParentIndex为sParentIndex的数据行

Dim dataRows() As DataRow = dvList.Table.Select("类型父项编号 = '" + strParentIndex + "'")

'循环添加TreeNode

For Each dr As DataRow In dataRows

tempNode = New TreeNode

tempNode.Text = dr("图书类型代码") "-" dr("图书类型名称")

'用TreeNode的Tag属性保存与此节点相关的数据

tempNode.Tag = CType(New treeNodeData(dr("图书类型代码"), _

dr("图书类型名称"), dr("图书类型说明"), _

dr("类型层次编号"), dr("类型父项编号")), Object)

currentId = dr("类型层次编号")

'添加节点

nodes.Add(tempNode)

'递归调用

initTrvTree(nodes(nodes.Count - 1).Nodes, currentId, dvList)

Next

Catch ex As Exception

MessageBox.Show("初始化TreeView失败")

End Try

End Sub

Public Class treeNodeData

'以下是TreeNodeData五个公有变量

Public BookTypeCode As String

Public BookTypeName As String

Public BookTypeExplain As String

Public ItemIndex As String

Public ParentIndex As String

'TreeNodeData类的构造函数

Sub New(ByVal strBookTypeCode As String, _

ByVal strBookTypeName As String, _

ByVal strBookTypeExplain As String, _

ByVal strItemIndex As String, _

ByVal strParentIndex As String)

BookTypeCode = strBookTypeCode

BookTypeName = strBookTypeName

BookTypeExplain = strBookTypeExplain

ItemIndex = strItemIndex

ParentIndex = strParentIndex

End Sub

End Class

Private Sub initializeTree()

Dim dt As New DataTable

Dim dvList As DataView

dt = bookTypeObj.getBookType()

dvList = dt.DefaultView

'初始化TreeView控件的各个节点

bookTypeObj.initTrvTree(trvList.Nodes, "-1", dvList)

'初始化TreeView控件的各个节点

trvList.Nodes(0).Tag = New bookAPP.treeNodeData("", "图书类型", "", "0", "")

bookTypeObj.initTrvTree(trvList.Nodes(0).Nodes, "0", dvList)

End Sub

VB.NET中使用AspNetPager控件的详细用法

AspNetPager简单使用方法 AspNetPager作为分页工具,常常用于绑定数据控件,如DataGrid , Repeater等

在这里,简单讲解下 绑定 Repeater 控件的方法,其余控件绑定方法类似:

'全局变量 i 用于 读取 数据集记录的条数(注意:读取一次就够了)

Dim i As New Integer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If i = 0 Then

con = New SqlConnection(ConfigurationManager.ConnectionStrings("NEWS_ConnectionString").ConnectionString)

con.Open()

cmd = New SqlCommand()

cmd.Connection = con

cmd.CommandText = "select count(*) from XWNRB "

'AspNetPager控件 可见

Me.AspNetPager1.Visible = True

'AspNetPager控件 每页显示大小为10条记录

Me.AspNetPager1.PageSize = 10

'AspNetPager控件 记录总的记录条数

Me.AspNetPager1.RecordCount = Convert.ToInt32(cmd.ExecuteScalar())

'AspNetPager控件 数据绑定

Me.SHOW_DATA_LIST()

i = i + 1

con.Close()

End If

End Sub

Protected Sub SHOW_DATA_LIST()

con = New SqlConnection(ConfigurationManager.ConnectionStrings("NEWS_ConnectionString").ConnectionString)

sql_Text = "select * from XWNRB where "

da = New SqlDataAdapter(sql_Text, con)

Dim ds As New Data.DataSet

'第一个参数为存储入的数据集为ds

'第二个参数为存储的起始记录序号

'第三个参数为存储的记录每页条数

'第四个参数为存储入的数据集ds中的具体某个表

da.Fill(ds, Me.AspNetPager1.PageSize * (Me.AspNetPager1.CurrentPageIndex - 1), Me.AspNetPager1.PageSize, "NEWS_LIST")

'真正绑定

Me.Repeater2.DataSource = ds.Tables("NEWS_LIST").DefaultView

Me.Repeater2.DataBind()

End Sub

'即每次点击新的页面,或者点击 Pre,Next,Last.....时候都会触发这个事件

Protected Sub AspNetPager1_PageChanged(ByVal src As Object, ByVal e As Wuqi.Webdiyer.PageChangedEventArgs) Handles AspNetPager1.PageChanged

'更新当前所在的页数序列

Me.AspNetPager1.CurrentPageIndex = e.NewPageIndex

'更新完后绑定

Me.SHOW_DATA_LIST()

End Sub

在vb.net如何使用parallel来提高处理任务的速度,麻烦举个例子谢谢

例子1:

Dim result As ParallelLoopResult = Parallel.[For](0, 10, Function(i) 

Console.WriteLine("{0}, task: {1} , thread: {2}", i, Task.CurrentId, Thread.CurrentThread.ManagedThreadId)

Thread.Sleep(10)

End Function)

Console.WriteLine(result.IsCompleted)

例子2:

Parallel.For(Of String)(0, 20, 

Function() 

Console.WriteLine("init thread {0},  task {1}", Thread.CurrentThread.ManagedThreadId, Task.CurrentId)

Return String.Format("t: {0}", Thread.CurrentThread.ManagedThreadId)

End Function, 

Function(i, pls, str) 

Console.WriteLine("body  i {0}  str1 {1}  thread {2}  task {3}", i, str, Thread.CurrentThread.ManagedThreadId, Task.CurrentId)

Return String.Format("i {0}", i)

End Function, 

Function(str1) 

Console.WriteLine("finally {0}", str1)

End Function)

vb.net的数据库连接

1·绑定数据源来进行连接

2.用代码连接

先到数据库建立一个数据库和相应的表

连接数据库的代码:

Dim str As String = "Data Source=服务器名;Initial Catalog=数据库名;Persist Security Info=True;User ID=;Password="

dim conn As SqlClient.SqlConnection

try

conn = New SqlClient.SqlConnection

conn.ConnectionString = str

conn.Open()

Return True

Catch ex As Exception

MsgBox(ex.ToString)

Return False

End Try

登录代码:Dim str As String = "Data Source=服务器名;Initial Catalog=数据库名;Persist Security Info=True;User ID=;Password="

dim conn As SqlClient.SqlConnection

conn = New SqlClient.SqlConnection

conn.ConnectionString = str

conn.Open()

sqlstr = "Select * From Amd Where AmdName='" TextBox1.Text "' And AmdPwd = '" TextBox2.Text "'"

Dim sqlcmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(sqlstr, conn)

Dim dr As SqlClient.SqlDataReader

dr = sqlcmd.ExecuteReader

If dr.Read = True Then '判断一条记录为真

kf.Show() '显示下个窗体

Me.Hide() ’隐藏当前窗体

Else

MessageBox.Show("输入信息有误!", "提示")

TextBox1.Text = ""

TextBox2.Text = ""

End If

VB.net 如何绑定许多button和数组

vb.net里没有像vb那样的控件数组。也就是说复制控件后粘贴没有提示你是否创建控件数组。

你可以试验下面的代码。

Form1.Designer.vb 设计器中的窗体代码如下,上面有六个button。最右边的用来改变前5个地text:

Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated() Partial Class Form1

#Region "Windows フォーム デザイナによって生成されたコード "

System.Diagnostics.DebuggerNonUserCode() Public Sub New()

MyBase.New()

'この呼び出しは、Windows フォーム デザイナで必要です。

InitializeComponent()

End Sub

'Form は、コンポーネント一覧に后処理を実行するために dispose をオーバーライドします。

System.Diagnostics.DebuggerNonUserCode() Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)

If Disposing Then

If Not components Is Nothing Then

components.Dispose()

End If

End If

MyBase.Dispose(Disposing)

End Sub

'Windows フォーム デザイナで必要です。

Private components As System.ComponentModel.IContainer

Public ToolTip1 As System.Windows.Forms.ToolTip

Public WithEvents Command2 As System.Windows.Forms.Button

Public WithEvents _Command1_4 As System.Windows.Forms.Button

Public WithEvents _Command1_3 As System.Windows.Forms.Button

Public WithEvents _Command1_2 As System.Windows.Forms.Button

Public WithEvents _Command1_1 As System.Windows.Forms.Button

Public WithEvents _Command1_0 As System.Windows.Forms.Button

Public WithEvents Command1 As Microsoft.VisualBasic.Compatibility.VB6.ButtonArray

'メモ: 以下のプロシージャは Windows フォーム デザイナで必要です。

'Windows フォーム デザイナを使って変更できます。

'コード エディタを使用して、変更しないでください。

System.Diagnostics.DebuggerStepThrough() Private Sub InitializeComponent()

Me.components = New System.ComponentModel.Container

Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)

Me.Command2 = New System.Windows.Forms.Button

Me._Command1_4 = New System.Windows.Forms.Button

Me._Command1_3 = New System.Windows.Forms.Button

Me._Command1_2 = New System.Windows.Forms.Button

Me._Command1_1 = New System.Windows.Forms.Button

Me._Command1_0 = New System.Windows.Forms.Button

Me.Command1 = New Microsoft.VisualBasic.Compatibility.VB6.ButtonArray(Me.components)

CType(Me.Command1, System.ComponentModel.ISupportInitialize).BeginInit()

Me.SuspendLayout()

'

'Command2

'

Me.Command2.BackColor = System.Drawing.SystemColors.Control

Me.Command2.Cursor = System.Windows.Forms.Cursors.Default

Me.Command2.ForeColor = System.Drawing.SystemColors.ControlText

Me.Command2.Location = New System.Drawing.Point(235, 176)

Me.Command2.Name = "Command2"

Me.Command2.RightToLeft = System.Windows.Forms.RightToLeft.No

Me.Command2.Size = New System.Drawing.Size(65, 25)

Me.Command2.TabIndex = 5

Me.Command2.Text = "Change"

Me.Command2.UseVisualStyleBackColor = False

'

'_Command1_4

'

Me._Command1_4.BackColor = System.Drawing.SystemColors.Control

Me._Command1_4.Cursor = System.Windows.Forms.Cursors.Default

Me._Command1_4.ForeColor = System.Drawing.SystemColors.ControlText

Me.Command1.SetIndex(Me._Command1_4, CType(4, Short))

Me._Command1_4.Location = New System.Drawing.Point(16, 176)

Me._Command1_4.Name = "_Command1_4"

Me._Command1_4.RightToLeft = System.Windows.Forms.RightToLeft.No

Me._Command1_4.Size = New System.Drawing.Size(93, 25)

Me._Command1_4.TabIndex = 4

Me._Command1_4.Text = "Command1"

Me._Command1_4.UseVisualStyleBackColor = False

'

'_Command1_3

'

Me._Command1_3.BackColor = System.Drawing.SystemColors.Control

Me._Command1_3.Cursor = System.Windows.Forms.Cursors.Default

Me._Command1_3.ForeColor = System.Drawing.SystemColors.ControlText

Me.Command1.SetIndex(Me._Command1_3, CType(3, Short))

Me._Command1_3.Location = New System.Drawing.Point(16, 137)

Me._Command1_3.Name = "_Command1_3"

Me._Command1_3.RightToLeft = System.Windows.Forms.RightToLeft.No

Me._Command1_3.Size = New System.Drawing.Size(93, 25)

Me._Command1_3.TabIndex = 3

Me._Command1_3.Text = "Command1"

Me._Command1_3.UseVisualStyleBackColor = False

'

'_Command1_2

'

Me._Command1_2.BackColor = System.Drawing.SystemColors.Control

Me._Command1_2.Cursor = System.Windows.Forms.Cursors.Default

Me._Command1_2.ForeColor = System.Drawing.SystemColors.ControlText

Me.Command1.SetIndex(Me._Command1_2, CType(2, Short))

Me._Command1_2.Location = New System.Drawing.Point(16, 96)

Me._Command1_2.Name = "_Command1_2"

Me._Command1_2.RightToLeft = System.Windows.Forms.RightToLeft.No

Me._Command1_2.Size = New System.Drawing.Size(93, 25)

Me._Command1_2.TabIndex = 2

Me._Command1_2.Text = "Command1"

Me._Command1_2.UseVisualStyleBackColor = False

'

'_Command1_1

'

Me._Command1_1.BackColor = System.Drawing.SystemColors.Control

Me._Command1_1.Cursor = System.Windows.Forms.Cursors.Default

Me._Command1_1.ForeColor = System.Drawing.SystemColors.ControlText

Me.Command1.SetIndex(Me._Command1_1, CType(1, Short))

Me._Command1_1.Location = New System.Drawing.Point(16, 56)

Me._Command1_1.Name = "_Command1_1"

Me._Command1_1.RightToLeft = System.Windows.Forms.RightToLeft.No

Me._Command1_1.Size = New System.Drawing.Size(93, 25)

Me._Command1_1.TabIndex = 1

Me._Command1_1.Text = "Command1"

Me._Command1_1.UseVisualStyleBackColor = False

'

'_Command1_0

'

Me._Command1_0.BackColor = System.Drawing.SystemColors.Control

Me._Command1_0.Cursor = System.Windows.Forms.Cursors.Default

Me._Command1_0.ForeColor = System.Drawing.SystemColors.ControlText

Me.Command1.SetIndex(Me._Command1_0, CType(0, Short))

Me._Command1_0.Location = New System.Drawing.Point(16, 16)

Me._Command1_0.Name = "_Command1_0"

Me._Command1_0.RightToLeft = System.Windows.Forms.RightToLeft.No

Me._Command1_0.Size = New System.Drawing.Size(93, 25)

Me._Command1_0.TabIndex = 0

Me._Command1_0.Text = "Command1"

Me._Command1_0.UseVisualStyleBackColor = False

'

'Form1

'

Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)

Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font

Me.BackColor = System.Drawing.SystemColors.Control

Me.ClientSize = New System.Drawing.Size(312, 213)

Me.Controls.Add(Me.Command2)

Me.Controls.Add(Me._Command1_4)

Me.Controls.Add(Me._Command1_3)

Me.Controls.Add(Me._Command1_2)

Me.Controls.Add(Me._Command1_1)

Me.Controls.Add(Me._Command1_0)

Me.Cursor = System.Windows.Forms.Cursors.Default

Me.Location = New System.Drawing.Point(4, 23)

Me.Name = "Form1"

Me.RightToLeft = System.Windows.Forms.RightToLeft.No

Me.Text = "Form1"

CType(Me.Command1, System.ComponentModel.ISupportInitialize).EndInit()

Me.ResumeLayout(False)

End Sub

#End Region

End Class

’==========================================

Form1中的代码如下:

Friend Class Form1

Inherits System.Windows.Forms.Form

Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click

Dim i As Object

'按钮标题数组。

Dim cArr() As String = New String() {"A", "B", "C", "D", "E", "F", "G"}

For i = 0 To Me.Command1.Count - 1

Me.Command1(i).Text = cArr(i)

Next

End Sub

End Class

VB.net如何动态获取菜单栏中的菜单名并用树型表示

添加:(先在加一个contextMenu,再它的添加子菜单的click事件编程)

Try

’使TreeView可以被编辑

TreeView1.LabelEdit = True

‘判断你是不是选定的是不可编辑的节点,我这里工种节点不可以被编辑,只有工种下级的

各个工种名称可以被编辑

If Trim(TreeView1.SelectedNode.Text) = "工种" Then

‘添加节点

AddNode = New TreeNode("请输入新工种名字")

TreeView1.SelectedNode.Nodes.Add(AddNode)

TreeView1.ExpandAll()

AddNode.BeginEdit()

TreeView1.LabelEdit = True

NodeAdded = True

End If

Catch err As Exception

MsgBox(err.ToString)

End Try

删除与添加类似,只是如果你的节点名字从其他处(如数据库)得来,那么你还需要更新数据库

编辑:

Private Sub TreeView1_BeforeLabelEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.NodeLabelEditEventArgs) Handles TreeView1.BeforeLabelEdit

TreeView1.LabelEdit = True ‘使可以编辑

AddNode = TreeView1.SelectedNode

End Sub

Private Sub TreeView1_AfterLabelEdit(ByVal sender As Object, ByVal e As System.windows.Forms.NodeLabelEditEventArgs) Handles TreeView1.AfterLabelEdit

Try

‘此时你改完了节点名字

TreeView1.SelectedNode.EndEdit(True)

If e.Label Is Nothing Then

'do nothing

ElseIf e.Node.Text = "工种" Then ‘工种不能改

e.CancelEdit() = True

‘e.Node.Text ,e.Label.ToString 一个是改前的名字一个是该后的名字,具体哪个对

哪个请查MSDN

ElseIf Trim(e.Node.Text) "工种" And e.Node.Text e.Label.ToString Then

If MsgBox("此操作会导致当前工种中的所有人员的工种都被更改,是否确定?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "警告") = MsgBoxResult.Yes Then

。。。。 ‘我的更改

MsgBox("更改成功!", MsgBoxStyle.OKOnly, "提示")

'Call InitTree() ‘有时要重新把treeview初始化一遍,视需求定

End If

End If

Catch err As Exception

MsgBox(err.ToString)

End Try

End Sub

其他:

挡treeview得到焦点时你可以使用ContextMenu,反之ContextMenu禁用

Private Sub TreeView1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.GotFocus

TreeView1.ContextMenu = ContextMenu1

End Sub

Private Sub TreeView1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.LostFocus

TreeView1.ContextMenu = Nothing

End Sub

注意:这里没有在ContextMenu菜单添加“更改”项,而是直接更改:即左键单击节点表示

选中,再单击一下就可以编辑了,更改之后单击他处就完成更改,和你在windows中更改文

件名字相似。


本文名称:vb.net中init,aspnet vb
分享网址:http://cxhlcq.com/article/phjcgi.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部