在datagridview中加载未绑定的组合框 [英] Loading unbound combo box in datagridview

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

问题描述

我有一个datagridview,它包含绑定字段和一个未绑定的组合框。 我需要根据绑定单元格的值加载具有不同值的组合框的内容。 执行此操作时,无论确定要加载内容的单元格的值如何,每行上的组合框都会加载最后一个值
。 有什么建议吗? 谢谢你

I have a datagridview that has bound fields and an unbound combo box.  I need to load the contents of the combo box with different values based on the value of a bound cell.  When doing this, the combo box on every row has the last values loaded no matter the value of the cell that determines what to load.  Any suggestions?  Thanks

对于每一行As DataGridViewRow在DataGridView1.Rows

            如果不是IsDBNull(row.Cells(4).Value)则为
                如果row.Cells(4).Value =" 1"然后是
                    RESPONSE.Items.Add(QUOT; FOR")

               &NBSP ;    RESPONSE.Items.Add(QUOT;反对")

               &NBSP ;    RESPONSE.Items.Add(QUOT; ABSTAIN")

               &NBSP ;    RESPONSE.Items.Add(QUOT; INVALID")

               &NBSP ;    RESPONSE.Items.Add(QUOT; NULL")

               结束如果

               如果row.Cells(4).Value =" 2"然后是
                    RESPONSE.Items.Add(QUOT;是")

               &NBSP ;    RESPONSE.Items.Add([否")

               &NBSP ;    RESPONSE.Items.Add(QUOT; ABSTAIN")

               &NBSP ;    RESPONSE.Items.Add(QUOT; INVALID")

               &NBSP ;    RESPONSE.Items.Add(" NULL")

               结束如果

           结束如果

       下一步

For Each row As DataGridViewRow In DataGridView1.Rows
            If Not IsDBNull(row.Cells(4).Value) Then
                If row.Cells(4).Value = "1" Then
                    RESPONSE.Items.Add("FOR")
                    RESPONSE.Items.Add("AGAINST")
                    RESPONSE.Items.Add("ABSTAIN")
                    RESPONSE.Items.Add("INVALID")
                    RESPONSE.Items.Add("NULL")
                End If
                If row.Cells(4).Value = "2" Then
                    RESPONSE.Items.Add("YES")
                    RESPONSE.Items.Add("NO")
                    RESPONSE.Items.Add("ABSTAIN")
                    RESPONSE.Items.Add("INVALID")
                    RESPONSE.Items.Add("NULL")
                End If
            End If
        Next

推荐答案

您好

这里有点疑惑,但是,最佳猜测如下。

A little confused on question here, but, best guess as follows.

假设Form上的一个ComboBox名为RESPONSE,并希望根据单元格中的值填充这些固定项目(这里我使用了第1列,因为我已经有一个DGV用于测试)。

Assuming one ComboBox on Form called RESPONSE, and wanting to populate with those fixed items depending on value in a cell(here I used column 1 as I already had a DGV for testing).

使用此代码,然后当用户将选择放入一行时,将相应地填充组合框。

Using this code, then when user places selection in a row, then the combobox will be populated accordingly.

  Private Sub DataGridView1_RowEnter(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
	RESPONSE.Items.Clear()
	Select Case CInt(DataGridView1("Roll Number", e.RowIndex).Value)
	  Case 1
		RESPONSE.Items.Add("FOR")
		RESPONSE.Items.Add("AGAINST")
		RESPONSE.Items.Add("ABSTAIN")
		RESPONSE.Items.Add("INVALID")
		RESPONSE.Items.Add("NULL")
	  Case 2
		RESPONSE.Items.Add("YES")
		RESPONSE.Items.Add("NO")
		RESPONSE.Items.Add("ABSTAIN")
		RESPONSE.Items.Add("INVALID")
		RESPONSE.Items.Add("NULL")
	End Select
  End Sub


这篇关于在datagridview中加载未绑定的组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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