Click here to Skip to main content
12,401,985 members (57,576 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB 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
vidkaat570
Comments
Shelby Robertson 21-Feb-13 13:18pm
   
Do you want to add a blank item to the combo box and have it selected by default?
ryanb31 21-Feb-13 15:37pm
   
As shelby said, add a blank item at position 0.
CHill60 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 22 Feb 2013
Copyright © CodeProject, 1999-2016
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