C/C++教程

ComboBox1 绑定手动创建的DataTable

本文主要是介绍ComboBox1 绑定手动创建的DataTable,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 

'**************************************************
'*过程名称:DT_PAFORMAL
'*功能说明:员工类别
'**************************************************
Public Function DT_PAFORMAL() As DataTable
Dim dt As New DataTable
Dim dc1 As DataColumn = New DataColumn("id", Type.GetType("System.String"))
Dim dc2 As DataColumn = New DataColumn("name", Type.GetType("System.String"))
dt.Columns.Add(dc1)
dt.Columns.Add(dc2)
Dim dr1 As DataRow = dt.NewRow()
dr1("id") = "1"
dr1("name") = "干部"
dt.Rows.Add(dr1)
Dim dr2 As DataRow = dt.NewRow()
dr2("id") = "2"
dr2("name") = "固定工"
dt.Rows.Add(dr2)
Dim dr3 As DataRow = dt.NewRow()
dr3("id") = "3"
dr3("name") = "合同工"
dt.Rows.Add(dr3)
Dim dr4 As DataRow = dt.NewRow()
dr4("id") = "4"
dr4("name") = "临时工"
dt.Rows.Add(dr4)
Dim dr5 As DataRow = dt.NewRow()
dr5("id") = "5"
dr5("name") = "外来务工"
dt.Rows.Add(dr5)
Return dt
End Function

 

'调用

CMB_PAFORMAL.DataSource = CL.DT_PAFORMAL.Copy
CMB_PAFORMAL.DisplayMember = "name"
CMB_PAFORMAL.ValueMember = "id"
CMB_PAFORMAL.SelectedIndex = -1

这篇关于ComboBox1 绑定手动创建的DataTable的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!