Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi,
 
Here is my code:
 
m_dtDelayedDeliveryDays = GetDelayedDeliveryDays()
        cmbDelayedDeliveryDays.SelectedIndex = -1
 
        For Each dr As DataRow In m_dtDelayedDeliveryDays.Rows
            Me.cmbDelayedDeliveryDays.Items.Add(dr("DeliveryDelayDays"))
        Next
        cmbDelayedDeliveryDays.DataSource = m_dtDelayedDeliveryDays
        cmbDelayedDeliveryDays.DisplayMember = "DeliveryDelayDays"
        cmbDelayedDeliveryDays.ValueMember = "DeliveryDelayDaysID"
 
        Dim delayID As Integer = m_objUIMgr.DeliveryDelayDaysID
 
        If delayID > 0 Then
 

            cmbDelayedDeliveryDays.SelectedIndex = delayID - 1
 

 
        End If
 
        'delayID = Nothing

My combo box has values like 0,3,7...When the form gets loaded it shud display empty.
 

    End Sub
I am trying to load my combo value from the database. Also i check whether the values are in the database already in the line
Dim delayID As Integer = m_objUIMgr.DeliveryDelayDaysID...This will return 0 if there is no ID stored before.
 
The above code works fine on retrieving . But when there is no ID in the datatable then my combo box displays by default value 0 instead of empty.Please help.
Posted 21-Feb-13 6:55am
vidkaat521
Comments
Shelby Robertson at 21-Feb-13 13:18pm
   
Do you want to add a blank item to the combo box and have it selected by default?
ryanb31 at 21-Feb-13 15:37pm
   
As shelby said, add a blank item at position 0.
CHill60 at 21-Feb-13 18:18pm
   
No you don't want a "blank item" ... try setting the SelectedIndex = -1.
So (I think)
If delayID > 0 Then
cmbDelayedDeliveryDays.SelectedIndex = delayID - 1
Else
cmbDelayedDeliveryDays.SelectedIndex = -1
End If

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

hi,
In the above code, you have checked condition that
 
If delayID > 0 Then

cmbDelayedDeliveryDays.SelectedIndex = delayID - 1

 
End If
 
and you said
Dim delayID As Integer = m_objUIMgr.DeliveryDelayDaysID
 
it returns as "0".
Hence, Condition is false. then how this coding will work?
 
You can try like:
If delayID >= 0 Then
 
cmbDelayedDeliveryDays.SelectedIndex = delayID - 1
 

End If
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 434
1 Nirav Prabtani 338
2 Abhinav S 170
3 PIEBALDconsult 160
4 Dave Kreskowiak 155
0 OriginalGriff 7,640
1 Sergey Alexandrovich Kryukov 6,836
2 Maciej Los 3,919
3 Peter Leow 3,698
4 CHill60 2,742


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 22 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100