如何在datagridview中为组合框分配值 [英] How to assign a value to combobox in a datagridview

查看:74
本文介绍了如何在datagridview中为组合框分配值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我在datagridview中填充了一个组合框。这很完美。我的问题是,如何在datagridview中为组合框分配特定值?我希望用户能够加载表单并显示已经显示的特定值,并选择已添加到组合框中的项目。

Hello,

I have populated a combobox in a datagridview. This works perfect. My issue is, how do i assign a certain value to the combobox in a datagridview? I want the user to be able to load the form and have a certain value already displayed with the option to choose items that have been added to the combobox.

For Each row In Me.DataGridView1.Rows
           row.Height = 40
           row.DefaultCellStyle.WrapMode = DataGridViewTriState.True
           Dim dgvcombo As DataGridViewComboBoxCell
           dgvcombo = row.Cells(2)
           row.Cells(0).Value = tasknum
           row.Cells(1).Value = GetScalarData("SELECT duedate FROM task WHERE capaID = '" & CAPAid & "' AND task = '" & tasknum & "'")
           For i = 0 To x.Count - 1
               dgvcombo.Items.Add(x(i))
           Next


           tasknum = tasknum + 1
       Next row





非常感谢任何帮助。



谢谢



Any help would be greatly appreciated.

Thank You

推荐答案

看看这里: DataGridViewComboBoxColumn类 [ ^ ]

在r的底部兴高采烈的页面,你会找到一个例子如何将数据绑定到 DataGridViewComboBoxColumn


dgvcombo.Value = dgvcombo.Items(0)



将选择您的第一件商品



A DataGridViewComboBoxCell 使用.Value

not .Text就像普通的ComboBox


will select the first of your items

A DataGridViewComboBoxCell uses .Value
not .Text like a normal ComboBox


这篇关于如何在datagridview中为组合框分配值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆