Click here to Skip to main content
16,020,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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. :)

VB
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)
Posted

1 solution

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.
 
Share this answer
 
v3
Comments
Lara_Mae 14-Aug-13 22:24pm    
i tried to put the value of mode in another variable... out side the loop .. only one mode, specifically the first one was fetched from the database. the other modes are not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900