填充由id过滤的数据网格内的组合框 [英] Populate combo box inside a datagrid filtered by id

查看:113
本文介绍了填充由id过滤的数据网格内的组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我吗?我的数据网格中有一个组合框,我需要在其中填充数据..我的问题是关于我的变量模式..如果mode = 1应该在组合框内但是如果不是(例如mode = 2或3或4)那么组合框内应该没有任何东西。我的代码无效。无论模式是1还是2还是其他数字我的组合框仍在填充数据。



PS:模式和总数的值来自另一个查询。请。不要困惑。 :)



Can someone help me with this?? there is a combobox inside my datagrid and i need to populate data in it.. my problem is about my variable mode.. if mode = 1 there should be inside the combobox but if its not (for example mode = 2 or 3 or 4) then there should be nothing inside the combobox. my code is not working. whether the mode is 1 or 2 or other number my combobox is still populating data.

PS: values of mode and total are from another query. pls. dont be confused. :)

Dim cmbDeb As New DataGridViewComboBoxColumn
cmbDeb.HeaderText = "Debit"

ReDim mode(0 To total)
For i = 0 To total
    mode(i) = dt.Rows(i)(0)

    If mode(i) = 1 Then
        SqlStr = "SELECT accountName FROM mst_Account"
        dt = qry.ExecuteSql(SqlStr)
        cmbDeb.Items.Add(dt.Rows(0).Item(0))
    Else
        'nothing must be inside the combobox
    End If

Next

Me.dgJP.Columns.Add(cmbDeb)

推荐答案

为什么要使用for循环?问题是因为for循环。



当i = 0的值时,你的cmbDeb将为空。
当i = 1时
,你的cmbDeb将被填满。

当i = 2的值时,你的cmbDeb将包含值因为它已经填满而值= 1

当i的值= 3,你的cmbDeb将包含值,因为它已经填满,而值= 1

等等。



和最后你向dgJP添加列。因此,当值为1时,cmbDeb的值将被填满。
why do you use for loop ? Issue is because of for loop.

when value of i = 0, your cmbDeb will be empty.
when value of i = 1, your cmbDeb will be filled up.
when value of i = 2, your cmbDeb will contain values because it is already filled up while value = 1
when value of i = 3, your cmbDeb will contain values because it is already filled up while value = 1
and so on.

and at the end you add columns to dgJP. So it will will the value of cmbDeb which is already filled up when value was 1.


这篇关于填充由id过滤的数据网格内的组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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