关于combobox

rainbowsoftware 2007-05-31 09:59:36
我将combobox与datagridview连接在一起,当选中datagridview中某一列中持单元格时combobox可见。
问题是,当我选中的列不同时,combobx中的内容也不同,其中一个列access中的某一字段绑定,还有一个是通过addrang加进去的,请问我该如何实现xombobox中有内容,随着列的不同自由改变?
...全文
370 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
rainbowsoftware 2007-06-05
  • 打赏
  • 举报
回复
我在datagridview中已经写一一条语句为
combobox1.text=DataGridView1.CurrentCell.Value 用这个事件在执行这一句时,不也触发吗?`
scow 2007-06-05
  • 打赏
  • 举报
回复
TextChanged
小人非君子 2007-06-05
  • 打赏
  • 举报
回复
datagridview有个click事件,你可以在这个事件里写
当选中datagridview中的一条记录的时候,你的combobox里的内容首先清空,(是remove还是别的什么命令,我记不大清了。你自己查查看)。然后你再将datagridview中选中的记录添加到combobox里。(用add命令)

每选中一条记录,你就让combobox执行这两条命令。这样你的combobox就能随着datagridview中的记录的改变而相应的变值了。
rainbowsoftware 2007-06-05
  • 打赏
  • 举报
回复
帮帮忙,高手
scow 2007-06-04
  • 打赏
  • 举报
回复
啥事件?
rainbowsoftware 2007-06-04
  • 打赏
  • 举报
回复
怎样写事件与之关联我想知道
scow 2007-06-04
  • 打赏
  • 举报
回复
combobox可以直接输入,取comboBox1.Text得到输入的值。
rainbowsoftware 2007-06-04
  • 打赏
  • 举报
回复
顶上去
rainbowsoftware 2007-06-04
  • 打赏
  • 举报
回复
就是响应我直接输入时的事件?
rainbowsoftware 2007-06-02
  • 打赏
  • 举报
回复
帮忙,还有不选择直接输入时用哪个事件呀?
guodabao 2007-06-02
  • 打赏
  • 举报
回复
学习
rainbowsoftware 2007-06-01
  • 打赏
  • 举报
回复
谢了,请问你对最顶上的目标有更好的解决方案吗?
scow 2007-06-01
  • 打赏
  • 举报
回复
If ComboBox1.DataSource = Nothing
to
If ComboBox1.DataSource is Nothing
rainbowsoftware 2007-06-01
  • 打赏
  • 举报
回复
由于刚才程序问题重发一遍
问题为::没有为 类型“DataTable” 和 'Nothing' 定义运算符“=”。
请高手帮忙解决
Private Sub DataGridView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.Click
If Button3.Text = "你" Then
If DataGridView1.CurrentCell.ColumnIndex = 2 Then
If ComboBox1.DataSource = Nothing Then‘问题出现处

ComboBox1.DataSource = ds.Tables(0)
ComboBox1.DisplayMember = "姓名"
ComboBox1.ValueMember = "姓名"

End If
ComboBox1.Left = DataGridView1.GetCellDisplayRectangle(DataGridView1.CurrentCell.ColumnIndex, DataGridView1.CurrentCell.RowIndex, True).Left
'(上两行是一行,叶面不够,写代码时要写在一行)
ComboBox1.Top = DataGridView1.GetCellDisplayRectangle(DataGridView1.CurrentCell.ColumnIndex, DataGridView1.CurrentCell.RowIndex, True).Top
' (上两行是一行,叶面不够,写代码时要写在一行)
ComboBox1.Text = DataGridView1.CurrentCell.Value '.ToString()
ComboBox1.Width = DataGridView1.GetCellDisplayRectangle(DataGridView1.CurrentCell.ColumnIndex, DataGridView1.CurrentCell.RowIndex, True).Width
'(上两行是一行,叶面不够,写代码时要写在一行)
ComboBox1.Visible = True
'Dim sp() As String = New String() {"1", "21", "30"}
' Dim installs() As String = New String() _
' {"Typical", "Compact", "Custom"}
' ComboBox1.Items.AddRange(installs)
ElseIf DataGridView1.CurrentCell.ColumnIndex = 3 Then
ComboBox1.DataSource = Nothing
ComboBox1.Items.Clear()
Dim ab As String() = New String() {"1", "2<", "3"}
ComboBox1.Items.AddRange(ab)
ComboBox1.Left = DataGridView1.GetCellDisplayRectangle(DataGridView1.CurrentCell.ColumnIndex, DataGridView1.CurrentCell.RowIndex, True).Left
'(上两行是一行,叶面不够,写代码时要写在一行)
ComboBox1.Top = DataGridView1.GetCellDisplayRectangle(DataGridView1.CurrentCell.ColumnIndex, DataGridView1.CurrentCell.RowIndex, True).Top
' (上两行是一行,叶面不够,写代码时要写在一行)
ComboBox1.Text = DataGridView1.CurrentCell.Value '.ToString()
ComboBox1.Width = DataGridView1.GetCellDisplayRectangle(DataGridView1.CurrentCell.ColumnIndex, DataGridView1.CurrentCell.RowIndex, True).Width
'(上两行是一行,叶面不够,写代码时要写在一行)
ComboBox1.Visible = True
'Dim sp() As String = New String() {"1", "21", "30"}
' Dim installs() As String = New String() _
' {"Typical", "Compact", "Custom"}
' ComboBox1.Items.AddRange(installs)
Else
ComboBox1.Visible = False
ComboBox1.Width = 0
ComboBox1.DataSource = Nothing
ComboBox1.Items.Clear()
End If


End If


End Sub

Private Sub ComboBox1_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted
If DataGridView1.CurrentCell.ColumnIndex = 2 Then
DataGridView1.CurrentCell.Value = ComboBox1.SelectedValue
Else
DataGridView1.CurrentCell.Value = ComboBox1.SelectedItem
End If
End Sub
rainbowsoftware 2007-06-01
  • 打赏
  • 举报
回复
娌℃湁涓?绫诲瀷鈥淒ataTable鈥?鍜?'Nothing' 瀹氫箟杩愮畻绗︹€?鈥濄€? Private Sub DataGridView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.Click
If Button3.Text = "浣? Then
If DataGridView1.CurrentCell.ColumnIndex = 2 Then
If ComboBox1.DataSource = Nothing Then

ComboBox1.DataSource = ds.Tables(0)
ComboBox1.DisplayMember = "濮撳悕"
ComboBox1.ValueMember = "濮撳悕"

End If
ComboBox1.Left = DataGridView1.GetCellDisplayRectangle(DataGridView1.CurrentCell.ColumnIndex, DataGridView1.CurrentCell.RowIndex, True).Left
'锛堜笂涓よ鏄竴琛岋紝鍙堕潰涓嶅锛屽啓浠g爜鏃惰鍐欏湪涓€琛岋級
ComboBox1.Top = DataGridView1.GetCellDisplayRectangle(DataGridView1.CurrentCell.ColumnIndex, DataGridView1.CurrentCell.RowIndex, True).Top
' 锛堜笂涓よ鏄竴琛岋紝鍙堕潰涓嶅锛屽啓浠g爜鏃惰鍐欏湪涓€琛岋級
ComboBox1.Text = DataGridView1.CurrentCell.Value '.ToString()
ComboBox1.Width = DataGridView1.GetCellDisplayRectangle(DataGridView1.CurrentCell.ColumnIndex, DataGridView1.CurrentCell.RowIndex, True).Width
'锛堜笂涓よ鏄竴琛岋紝鍙堕潰涓嶅锛屽啓浠g爜鏃惰鍐欏湪涓€琛岋級
ComboBox1.Visible = True
'Dim sp() As String = New String() {"1", "21", "30"}
' Dim installs() As String = New String() _
' {"Typical", "Compact", "Custom"}
' ComboBox1.Items.AddRange(installs)
ElseIf DataGridView1.CurrentCell.ColumnIndex = 3 Then
ComboBox1.DataSource = Nothing
ComboBox1.Items.Clear()
Dim ab As String() = New String() {"1", "2<", "3"}
ComboBox1.Items.AddRange(ab)
ComboBox1.Left = DataGridView1.GetCellDisplayRectangle(DataGridView1.CurrentCell.ColumnIndex, DataGridView1.CurrentCell.RowIndex, True).Left
'锛堜笂涓よ鏄竴琛岋紝鍙堕潰涓嶅锛屽啓浠g爜鏃惰鍐欏湪涓€琛岋級
ComboBox1.Top = DataGridView1.GetCellDisplayRectangle(DataGridView1.CurrentCell.ColumnIndex, DataGridView1.CurrentCell.RowIndex, True).Top
' 锛堜笂涓よ鏄竴琛岋紝鍙堕潰涓嶅锛屽啓浠g爜鏃惰鍐欏湪涓€琛岋級
ComboBox1.Text = DataGridView1.CurrentCell.Value '.ToString()
ComboBox1.Width = DataGridView1.GetCellDisplayRectangle(DataGridView1.CurrentCell.ColumnIndex, DataGridView1.CurrentCell.RowIndex, True).Width
'锛堜笂涓よ鏄竴琛岋紝鍙堕潰涓嶅锛屽啓浠g爜鏃惰鍐欏湪涓€琛岋級
ComboBox1.Visible = True
'Dim sp() As String = New String() {"1", "21", "30"}
' Dim installs() As String = New String() _
' {"Typical", "Compact", "Custom"}
' ComboBox1.Items.AddRange(installs)
Else
ComboBox1.Visible = False
ComboBox1.Width = 0
ComboBox1.DataSource = Nothing
ComboBox1.Items.Clear()
End If


End If


End Sub
Private Sub ComboBox1_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted
If DataGridView1.CurrentCell.ColumnIndex = 2 Then
DataGridView1.CurrentCell.Value = ComboBox1.SelectedValue
Else
DataGridView1.CurrentCell.Value = ComboBox1.SelectedItem
End If
End Sub
rainbowsoftware 2007-05-31
  • 打赏
  • 举报
回复
能否给段示例代码
新鲜鱼排 2007-05-31
  • 打赏
  • 举报
回复
根据选择行进行Checkbox的刷新。

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧