vb.net后期绑定的简单介绍

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中的combobox数据绑定问题

使用SelectedIndexChanged事件

Private Sub cbxBigDept_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

dim strBM as string

strBM=cbxBigDept.selectedValue ' 获得当前大部门名称

Dim myConn as SqlConnection = new sqlconnection(".......")

myConn.Open()

Dim myCmd as string = "select 小部门 from 小部门表 Where 大部门='" strBM "'"

Dim myAdapter as SqlDataAdapter = new SqlDataAdapter(myCmd,myConn)

Dim myDataSet as DataSet = new DataSet

myAdapter.Fill(myDataSet)

Me.cbxSonDept.DataSource = myAdapter.Table(0)

Me.cbxSonDept.ValueMember = "小部门"

myConn.Close

End Sub

祝你成功!

vb.net中关于combobox数据绑定的问题

源码给你,采纳 不谢

等下,我好想发现了什么 你是想用comb 控件来显示列数据?

这有点不切实际

用datagridview控件来显示吧(举个例子给你 excel 表)

dim xb as excel.workbook

dim xp as excel.application

dim column as long

Dim index As Integer = DataGridView1.Rows.Add()

xb=xp.workbook.open("你的excel数据表")

column=xb.columns.count

for j as integer= 1 to column

if xb.rows.cells(1,j)=comb1.selectedvalue then

DataGridView1.Rows(index).Cells(j - 1).Value = xp.rows("1").Cells(j - 1).Value

xb.close(true)

xp.close(true)

xb=nothing

xp=nothing

采纳后可以追问

VB.NET中怎麼用代码实现DataGridview的数据绑定?

一般来说:连接数据库这一块都做成DLL,这样方便

在配置文件app.config中加入

//m_SqlPath

存放SQL语句的XML文件

Dim

sqlHelper

As

New

SQLHelper("LotDBConnection")

Dim

sqlRead

As

New

ResourceHelper

Dim

ht

As

New

Hashtable

Dim

strSQL

As

String

Try

'设置SQL文参数

ht.Clear()

ht.Add(ColumnName.USER_ID.ToString,

Trim(Me.txtUserID.Text))

ht.Add(ColumnName.USER_NAME.ToString,

Trim(Me.txtUserName.Text))

'数据查询

strSQL

=

sqlRead.GetSQLSentence("GetUserList",

m_SqlPath,

ht)

ds

=

sqlHelper.ExecuteDataSet(strSQL)

If

ds.Tables(0).Rows.Count

=

Then

MessageBox

.Show

("数据不存在");

Else

'数据绑定

dgvUserMeisai.DataSource

=

ds.Tables(0)

End

If

Catch

ex

As

Exception

MessageBox

.Show

(ex.Message

);

Finally

sqlHelper

=

Nothing

sqlRead

=

Nothing

ht

=

Nothing

End

Try

vb.net动态添加控件,并且绑定了一些事件,这些事件只能对最新生成的控件做修改,之前生成的无法修改

比如说这样添加的计时器:

Dim Timer1 As New Timer

你要在合适的地方开始,比如窗体Load事件中,这样:

Timer1.Interval = 1000 '单位毫秒,1000毫秒=1秒

Timer1.Enabled = True '启用计时器

然后在代码窗口上方下拉列表里选择Timer1的Tick事件,自动添加代码:

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

End Sub

这是计时器触发的事件,每秒触发一次,在这里面输入循环判断是否有日程即可。提示:你可以用Now对象获取当前的日期和时间。

.net技术:C#.NET与VB.NET区别

1、.NET是一个平台,一个抽象的平台的概念。

.NET平台其本身实现的方式其实还是库,抽象层面上来看是一个平台。

本人理解的.NET核心就是.NET Framwork。

.NET Framework包括两个关键组成元素:

a.Common Language Runtime,公共语言运行时(CLR)-提供内在管理,代码安全性检测等功能

b..NET Framework Class Library,.NET框架类库(FLC)-提供大量应用类库,提高开发效率

学习.NET Framework 是所有.NET 开发人员都必须的,否则开发.NET程序永远都是停留在‘外功’的招式,NET Framework 是.NET开发高手的‘内功’修行之一。 

2、C#是一个程序设计语言,仅仅是一个语言。

程序设计语言仅仅是为了方便开发人员和计算机沟通的工具,虽然C#语法相对C和C++要多一些,但是相对来看C#语法都比较固定,这样使用起来却都很容易。我认可一位朋友说的,C#的语法更严谨!

这里回过来看看.NET和C#的关系,不得不提的是.NET程序的执行过程。

C#符合.NET CLR中的公共语言运行规范。CLS:common language specification,当然所有的.NET Language都是符合这个规范的例如:VB.NET、XAML和C++/CLI....等等。

VB.NET封装的程度更加高一些。比如可以很容易的使用集合类型。而到了C#就不得不写一个类,实现IList,ICollection和IEnumerable接口,然后再写方法。这样也就用C#实现了一个功能和VB.NET一样的集合类。也就是说,用VB.NET是半路出家,C#是从头开始。当然这也决定了在设计时的思路。

C#需要符合.NET CLS,是因为.NET CLR和JAVA 虚拟机类似,有一个中间语言共机器来执行。所有不同语言的.NET代码在执行前会被编译成同样的中间语言(MSIL),所以所有.NET支持语言都必须符合符合CLS规范。

P.S:如果做.NET 3.0 XAML开发的朋友,可以尝试下ildasm.exe看看XAML的应用程序,会发现原来XAML其实很简单。  

3、ASP.NET是一个网站开发的技术,仅仅是.NET框架中的一个应用模型。


分享标题:vb.net后期绑定的简单介绍
链接分享:http://ybzwz.com/article/heppdo.html