Datagridview框组合框 [英] Datagridview box combo box
本文介绍了Datagridview框组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个datagridview组合框列,Read Only属性设置为False。
我需要在组合框中插入值(比如一,二) ,三等)并且我还需要组合框来显示存储在变量中的certian值(比如dim abc as string =value)
我需要组合框,用于在表单加载时显示存储在abc中的值。
请告知如何完成这两项任务。
谢谢
Hi,
I have a datagridview combo box column with Read Only property set to False.
I need to insert values to the combo box (say One, Two, Three etc.) and also I need the combo box to display a certian value stored in a variable (say dim abc as string="value")
I need the combo box to display value stored in abc when the form loads.
Please advise how to achieve these two tasks.
Thanks
推荐答案
嗨试试这个
Hi try this
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Call LoadDataInComboBox()
Dim int As Int32 = Me.DataGridView1.Rows.Add()
Dim FirstRow As DataGridViewRow = Me.DataGridView1.Rows(int)
FirstRow.Cells(Column1.Index).Value = "Two"
End Sub
Sub LoadDataInComboBox()
Dim cboColumn As DataGridViewComboBoxColumn = Me.DataGridView1.Columns(Column1.Index)
cboColumn.Items.Add("One")
cboColumn.Items.Add("Two")
cboColumn.Items.Add("Three")
'or you can load any array or collection
Dim values As String() = New String() {"One", "Two", "Three"}
cboColumn.DataSource = values
'you can specify the display and value memer
'cboColumn.ValueMember = "IdField"
'cboColumn.DisplayMember = "DisplayField"
End Sub
这篇关于Datagridview框组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文