我希望这个DatagrIDVIEwComboBoxcolumn也应该使用datareader填充.
请建议如何使用Datareader将项添加到DatagrIDVIEwComboBoxcolumn.
以下是我尝试过的代码.
这里的博士是sqlDatareader
DatagrIDvIEw.Rows.Add(dr("Column1").ToString,dr("Column2"),dr("DatagrIDVIEwComboBoxcolumn "))
但是,当我添加这种方式我在DatagrIDVIEwComboBoxcolumn列上获取错误.
请建议
Dim dtProductInventory As New System.Data.Datatable Dim dtProducts As New System.Data.Datatable Using objsqlServer As New System.Data.sqlClIEnt.sqlConnection("Server=LOCALHOST\sqlEXPRESS; Integrated Security=sspI;Initial Catalog=AdventureWorks") objsqlServer.open() Dim sqlCmd As New System.Data.sqlClIEnt.sqlCommand("select * from production.ProductInventory",objsqlServer) dtProductInventory.Load(sqlCmd.ExecuteReader) sqlCmd.CommandText = "Select * from production.product" dtProducts.Load(sqlCmd.ExecuteReader) End Using DataGrIDVIEw1.autoGenerateColumns = False DataGrIDVIEw1.DataSource = dtProductInventory Dim colProductIDCombo As New System.windows.Forms.DataGrIDVIEwComboBoxColumn() colProductIDCombo.DataSource = dtProducts colProductIDCombo.displayMember = "name" colProductIDCombo.ValueMember = "ProductID" colProductIDCombo.DataPropertyname = "ProductID" colProductIDCombo.headerText = "ProductIDCombo" DataGrIDVIEw1.Columns.Add(colProductIDCombo) Dim colProductID As New System.windows.Forms.DataGrIDVIEwTextBoxColumn() colProductID.DataPropertyname = "ProductID" colProductID.headerText = "ProductID" DataGrIDVIEw1.Columns.Add(colProductID) Dim colShelf As New System.windows.Forms.DataGrIDVIEwTextBoxColumn() colShelf.DataPropertyname = "Shelf" colShelf.headerText = "Shelf" DataGrIDVIEw1.Columns.Add(colShelf) Dim colQuantity As New System.windows.Forms.DataGrIDVIEwTextBoxColumn() colQuantity.DataPropertyname = "Quantity" colQuantity.headerText = "Quantity" DataGrIDVIEw1.Columns.Add(colQuantity)总结
以上是内存溢出为你收集整理的vb.net – 如何在运行时在DatagridView的DatagridViewComboboxColumn中添加Items全部内容,希望文章能够帮你解决vb.net – 如何在运行时在DatagridView的DatagridViewComboboxColumn中添加Items所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)