来源:http://www.java2s.com/Code/VBAPI/System.Data/DataTableColumnsAdd.htm
imports System.Data.oleDb
imports System.windows.Forms
publicclass BindDatatableToControl
publicSharedSub Main
Application.Run ( NewForm1 )
EndSub
Endclass
Publicclass Form1
'T hedatasource.
Private m_Contactstable As Datatable
'T hedatasource 's CurrencyManager.
Private m_CurrencyManager As CurrencyManager
PrivateSub Form1_Load ( ByValsender As System.Object,_
ByVale As System.EventArgs ) HandlesMyBase.Load
'M akeaDatatable.
m_Contactstable=NewDatatable ( "Contacts" )
'A ddcolumns.
m_Contactstable.Columns.Add ( "Firstname" ,GetType ( String ))
m_Contactstable.Columns.Add ( "Lastname" ,GetType ( String ))
m_Contactstable.Columns.Add ( "Street" ,GetType ( String ))
m_Contactstable.Columns.Add ( "City" ,GetType ( String ))
m_Contactstable.Columns.Add ( "State" ,GetType ( String ))
m_Contactstable.Columns.Add ( "Zip" ,GetType ( String ))
'M akethecombinedFirstname/Lastnameunique.
Dim first_last_columns () As DataColumn= { _
m_Contactstable.Columns ( "Firstname" ) ,_
m_Contactstable.Columns ( "Lastname" ) _
}
m_Contactstable.Constraints.Add ( _
NewUniqueConstraint ( first_last_columns ))
'M akesomecontactdata.
m_Contactstable.Rows.Add ( NewObject (){ "A" , "B" , "C" , "D" , "E" , "11111" })
m_Contactstable.Rows.Add ( NewObject (){ "F" , "G" , "H" , "I" , "J" , "22222" })
m_Contactstable.Rows.Add ( NewObject (){ "K" , "L" , "M" , "N" , "O" , "33333" })
m_Contactstable.Rows.Add ( NewObject (){ "P" , "Q" , "R" , "S" , "T" , "44444" })
m_Contactstable.Rows.Add ( NewObject (){ "U" , "V" , "W" , "X" , "Y" , "55555" })
m_Contactstable.Rows.Add ( NewObject (){ "Z" , "A" , "66666" })
m_Contactstable.Rows.Add ( NewObject (){ "E" , "F" , "77777" })
m_Contactstable.Rows.Add ( NewObject (){ "J" , "K" , "88888" })
'B indtocontrols.
txtFirstname.DataBindings.Add ( "Text" ,m_Contactstable, "Firstname" )
txtLastname.DataBindings.Add ( "Text" , "Lastname" )
txtStreet.DataBindings.Add ( "Text" , "Street" )
txtCity.DataBindings.Add ( "Text" , "City" )
txtState.DataBindings.Add ( "Text" , "State" )
txtZip.DataBindings.Add ( "Text" , "Zip" )
'S aveareferencetotheCurrencyManager.
m_CurrencyManager=_
DirectCast ( Me.BindingContext ( m_Contactstable ) ,CurrencyManager )
EndSub
PrivateSub btnFirst_Click ( ByValsender As System.Object,_
ByVale As System.EventArgs ) HandlesbtnFirst.Click
m_CurrencyManager.position= 0
EndSub
PrivateSub btnPrev_Click ( ByValsender As System.Object,_
ByVale As System.EventArgs ) HandlesbtnPrev.Click
m_CurrencyManager.position-= 1
EndSub
PrivateSub btnNext_Click ( ByValsender As System.Object,_
ByVale As System.EventArgs ) HandlesbtnNext.Click
m_CurrencyManager.position+= 1
EndSub
PrivateSub btnLast_Click ( ByValsender As System.Object,_
ByVale As System.EventArgs ) HandlesbtnLast.Click
m_CurrencyManager.position=m_CurrencyManager.Count- 1
EndSub
'A dda new record.
PrivateSub btnAdd_Click ( ByValsender As System.Object,_
ByVale As System.EventArgs ) HandlesbtnAdd.Click
m_CurrencyManager.AddNew ()
EndSub
PrivateSub btnDelete_Click ( ByValsender As System.Object,_
ByVale As System.EventArgs ) HandlesbtnDelete.Click
If MsgBox ( "Areyousureyouwanttodeletethisrecord?" ,_
MsgBoxStyle.QuestionorMsgBoxStyle.YesNo,_
"ConfirmDelete?" ) =MsgBoxResult.Yes_
Then
m_CurrencyManager.RemoveAt ( m_CurrencyManager.position )
EndIf
EndSub
EndClass
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated () >_
Partial Publicclass Form1
inherits System.windows.Forms.Form
'Fo rmoverrIDesdisposetocleanupthecomponentList.
<System.Diagnostics.DeBUGgerNonUserCode () >_
Protected OverloadsOverrIDes Sub dispose ( ByValdisposing As Boolean )
If disposingAndAlsocomponentsIsNotnothingThen
components.dispose ()
EndIf
MyBase.dispose ( disposing )
EndSub
'Re quiredbythewindowsFormDesigner
Private components As System.ComponentModel.IContainer
'NO TE:Thefollowing procedure isrequiredbythewindowsFormDesigner
'It canbemodifIEd using thewindowsFormDesigner.
'Do notmodifyit using thecodeeditor.
<System.Diagnostics.DeBUGgerStepThrough () >_
PrivateSub InitializeComponent ()
Me.Label6=NewSystem.windows.Forms.Label
Me.Label5=NewSystem.windows.Forms.Label
Me.Label4=NewSystem.windows.Forms.Label
Me.Label3=NewSystem.windows.Forms.Label
Me.Label2=NewSystem.windows.Forms.Label
Me.Label1=NewSystem.windows.Forms.Label
Me.btnDelete=NewSystem.windows.Forms.button
Me.btnAdd=NewSystem.windows.Forms.button
Me.btnLast=NewSystem.windows.Forms.button
Me.btnNext=NewSystem.windows.Forms.button
Me.btnPrev=NewSystem.windows.Forms.button
Me.btnFirst=NewSystem.windows.Forms.button
Me.txtZip=NewSystem.windows.Forms.TextBox
Me.txtState=NewSystem.windows.Forms.TextBox
Me.txtCity=NewSystem.windows.Forms.TextBox
Me.txtStreet=NewSystem.windows.Forms.TextBox
Me.txtLastname=NewSystem.windows.Forms.TextBox
Me.txtFirstname=NewSystem.windows.Forms.TextBox
Me.SuspendLayout ()
'
'La bel6
'
Me.Label6.autoSize=True
Me.Label6.Location=NewSystem.Drawing.Point ( 176 , 104 )
Me.Label6.name= "Label6"
Me.Label6.Size=NewSystem.Drawing.Size ( 22 , 13 )
Me.Label6.TabIndex= 35
Me.Label6.Text= "Zip"
'
'La bel5
'
Me.Label5.autoSize=True
Me.Label5.Location=NewSystem.Drawing.Point ( 8 , 104 )
Me.Label5.name= "Label5"
Me.Label5.Size=NewSystem.Drawing.Size ( 32 , 13 )
Me.Label5.TabIndex= 34
Me.Label5.Text= "State"
'
'La bel4
'
Me.Label4.autoSize=True
Me.Label4.Location=NewSystem.Drawing.Point ( 8 , 80 )
Me.Label4.name= "Label4"
Me.Label4.Size=NewSystem.Drawing.Size ( 24 , 13 )
Me.Label4.TabIndex= 33
Me.Label4.Text= "City"
'
'La bel3
'
Me.Label3.autoSize=True
Me.Label3.Location=NewSystem.Drawing.Point ( 8 , 56 )
Me.Label3.name= "Label3"
Me.Label3.Size=NewSystem.Drawing.Size ( 35 , 13 )
Me.Label3.TabIndex= 32
Me.Label3.Text= "Street"
'
'La bel2
'
Me.Label2.autoSize=True
Me.Label2.Location=NewSystem.Drawing.Point ( 8 , 32 )
Me.Label2.name= "Label2"
Me.Label2.Size=NewSystem.Drawing.Size ( 58 , 13 )
Me.Label2.TabIndex= 31
Me.Label2.Text= "Lastname"
'
'La bel1
'
Me.Label1.autoSize=True
Me.Label1.Location=NewSystem.Drawing.Point ( 8 , 8 )
Me.Label1.name= "Label1"
Me.Label1.Size=NewSystem.Drawing.Size ( 57 , 13 )
Me.Label1.TabIndex= 30
Me.Label1.Text= "Firstname"
'
'bt nDelete
'
Me.btnDelete.Location=NewSystem.Drawing.Point ( 240 , 144 )
Me.btnDelete.name= "btnDelete"
Me.btnDelete.Size=NewSystem.Drawing.Size ( 32 , 24 )
Me.btnDelete.TabIndex= 29
Me.btnDelete.Text= "X"
'
'bt nAdd
'
Me.btnAdd.Location=NewSystem.Drawing.Point ( 200 , 144 )
Me.btnAdd.name= "btnAdd"
Me.btnAdd.Size=NewSystem.Drawing.Size ( 32 , 24 )
Me.btnAdd.TabIndex= 28
Me.btnAdd.Text= "+"
'
'bt nLast
'
Me.btnLast.Location=NewSystem.Drawing.Point ( 104 , 144 )
Me.btnLast.name= "btnLast"
Me.btnLast.Size=NewSystem.Drawing.Size ( 32 , 24 )
Me.btnLast.TabIndex= 27
Me.btnLast.Text= ">>"
'
'bt nNext
'
Me.btnNext.Location=NewSystem.Drawing.Point ( 72 , 144 )
Me.btnNext.name= "btnNext"
Me.btnNext.Size=NewSystem.Drawing.Size ( 32 , 24 )
Me.btnNext.TabIndex= 26
Me.btnNext.Text= ">"
'
'bt nPrev
'
Me.btnPrev.Location=NewSystem.Drawing.Point ( 40 , 144 )
Me.btnPrev.name= "btnPrev"
Me.btnPrev.Size=NewSystem.Drawing.Size ( 32 , 24 )
Me.btnPrev.TabIndex= 25
Me.btnPrev.Text= "<"
'
'bt nFirst
'
Me.btnFirst.Location=NewSystem.Drawing.Point ( 8 , 144 )
Me.btnFirst.name= "btnFirst"
Me.btnFirst.Size=NewSystem.Drawing.Size ( 32 , 24 )
Me.btnFirst.TabIndex= 24
Me.btnFirst.Text= "<<"
'
'tx tZip
'
Me.txtZip.Anchor=CType ((( System.windows.Forms.AnchorStyles.topOrSystem.windows.Forms.AnchorStyles.left ) _
OrSystem.windows.Forms.AnchorStyles.Right ) ,System.windows.Forms.AnchorStyles )
Me.txtZip.Location=NewSystem.Drawing.Point ( 200 , 104 )
Me.txtZip.name= "txtZip"
Me.txtZip.Size=NewSystem.Drawing.Size ( 72 , 20 )
Me.txtZip.TabIndex= 23
'
'tx tState
'
Me.txtState.Location=NewSystem.Drawing.Point ( 72 , 104 )
Me.txtState.name= "txtState"
Me.txtState.Size=NewSystem.Drawing.Size ( 32 , 20 )
Me.txtState.TabIndex= 22
'
'tx tCity
'
Me.txtCity.Anchor=CType ((( System.windows.Forms.AnchorStyles.topOrSystem.windows.Forms.AnchorStyles.left ) _
OrSystem.windows.Forms.AnchorStyles.Right ) ,System.windows.Forms.AnchorStyles )
Me.txtCity.Location=NewSystem.Drawing.Point ( 72 , 80 )
Me.txtCity.name= "txtCity"
Me.txtCity.Size=NewSystem.Drawing.Size ( 200 , 20 )
Me.txtCity.TabIndex= 21
'
'tx tStreet
'
Me.txtStreet.Anchor=CType ((( System.windows.Forms.AnchorStyles.topOrSystem.windows.Forms.AnchorStyles.left ) _
OrSystem.windows.Forms.AnchorStyles.Right ) ,System.windows.Forms.AnchorStyles )
Me.txtStreet.Location=NewSystem.Drawing.Point ( 72 , 56 )
Me.txtStreet.name= "txtStreet"
Me.txtStreet.Size=NewSystem.Drawing.Size ( 200 , 20 )
Me.txtStreet.TabIndex= 20
'
'tx tLastname
'
Me.txtLastname.Anchor=CType ((( System.windows.Forms.AnchorStyles.topOrSystem.windows.Forms.AnchorStyles.left ) _
OrSystem.windows.Forms.AnchorStyles.Right ) ,System.windows.Forms.AnchorStyles )
Me.txtLastname.Location=NewSystem.Drawing.Point ( 72 , 32 )
Me.txtLastname.name= "txtLastname"
Me.txtLastname.Size=NewSystem.Drawing.Size ( 200 , 20 )
Me.txtLastname.TabIndex= 19
'
'tx tFirstname
'
Me.txtFirstname.Anchor=CType ((( System.windows.Forms.AnchorStyles.topOrSystem.windows.Forms.AnchorStyles.left ) _
OrSystem.windows.Forms.AnchorStyles.Right ) ,System.windows.Forms.AnchorStyles )
Me.txtFirstname.Location=NewSystem.Drawing.Point ( 72 , 8 )
Me.txtFirstname.name= "txtFirstname"
Me.txtFirstname.Size=NewSystem.Drawing.Size ( 200 , 20 )
Me.txtFirstname.TabIndex= 18
'
'Fo rm1
'
Me.autoScaleDimensions=NewSystem.Drawing.Sizef ( 6.0 !, 13.0 ! )
Me.autoScaleMode=System.windows.Forms.autoScaleMode.Font
Me.ClIEntSize=NewSystem.Drawing.Size ( 278 , 175 )
Me.Controls.Add ( Me.Label6 )
Me.Controls.Add ( Me.Label5 )
Me.Controls.Add ( Me.Label4 )
Me.Controls.Add ( Me.Label3 )
Me.Controls.Add ( Me.Label2 )
Me.Controls.Add ( Me.Label1 )
Me.Controls.Add ( Me.btnDelete )
Me.Controls.Add ( Me.btnAdd )
Me.Controls.Add ( Me.btnLast )
Me.Controls.Add ( Me.btnNext )
Me.Controls.Add ( Me.btnPrev )
Me.Controls.Add ( Me.btnFirst )
Me.Controls.Add ( Me.txtZip )
Me.Controls.Add ( Me.txtState )
Me.Controls.Add ( Me.txtCity )
Me.Controls.Add ( Me.txtStreet )
Me.Controls.Add ( Me.txtLastname )
Me.Controls.Add ( Me.txtFirstname )
Me.name= "Form1"
Me.Text= "UseCurrencyManager"
Me.ResumeLayout ( False )
Me.Performlayout ()
EndSub
FrIEnDWithEventsLabel6 As System.windows.Forms.Label
FrIEnDWithEventsLabel5 As System.windows.Forms.Label
FrIEnDWithEventsLabel4 As System.windows.Forms.Label
FrIEnDWithEventsLabel3 As System.windows.Forms.Label
FrIEnDWithEventsLabel2 As System.windows.Forms.Label
FrIEnDWithEventsLabel1 As System.windows.Forms.Label
FrIEnDWithEventsbtnDelete As System.windows.Forms.button
FrIEnDWithEventsbtnAdd As System.windows.Forms.button
FrIEnDWithEventsbtnLast As System.windows.Forms.button
FrIEnDWithEventsbtnNext As System.windows.Forms.button
FrIEnDWithEventsbtnPrev As System.windows.Forms.button
FrIEnDWithEventsbtnFirst As System.windows.Forms.button
FrIEnDWithEventstxtZip As System.windows.Forms.TextBox
FrIEnDWithEventstxtState As System.windows.Forms.TextBox
FrIEnDWithEventstxtCity As System.windows.Forms.TextBox
FrIEnDWithEventstxtStreet As System.windows.Forms.TextBox
FrIEnDWithEventstxtLastname As System.windows.Forms.TextBox
FrIEnDWithEventstxtFirstname As System.windows.Forms.TextBox
EndClass 总结
以上是内存溢出为你收集整理的VB.net中DataTable.Columns.Add的数据类型全部内容,希望文章能够帮你解决VB.net中DataTable.Columns.Add的数据类型所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)