Click here to Skip to main content
11,649,522 members (78,935 online)
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
vidkaat561
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 OriginalGriff 354
1 F-ES Sitecore 344
2 Kornfeld Eliyahu Peter 319
3 CPallini 290
4 Maciej Los 269
0 OriginalGriff 1,577
1 Sergey Alexandrovich Kryukov 1,087
2 CPallini 1,015
3 DamithSL 996
4 jyo.net 994


Advertise | Privacy | Mobile
Web04 | 2.8.150804.4 | Last Updated 22 Feb 2013
Copyright © CodeProject, 1999-2015
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