Click here to Skip to main content
11,639,126 members (68,536 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi,

I have a scenario:I loaded my combox box with the datatable in my Form Load as below:

m_dtDelayedDeliveryDays = GetDelayedDeliveryDays()
 

 
       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"

In also i am able to pick the Id based on the user selection as below:
Private Sub cmbDelayedDeliveryDays_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbDelayedDeliveryDays.SelectedIndexChanged
 
        cmbDelayedDeliveryDays.Refresh()
        Dim selectedDataRow As DataRow = DirectCast(cmbDelayedDeliveryDays.SelectedItem, DataRowView).Row
        Dim delayId As Integer = Convert.ToInt32(selectedDataRow("DeliveryDelayDaysID"))
 

    End Sub
My combo box is loaded with values like 0,3,7,15,20,30..
With the above code my combo box is with default value 0. I want me combo box to be empty by default.

Please help.

Thanks.
Posted 19-Feb-13 5:18am
vidkaat561

1 solution

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

Solution 1

After
cmbDelayedDeliveryDays.ValueMember = "DeliveryDelayDaysID"
put the following
cmbDelayedDeliveryDays..SelectedIndex = -1
In Sub cmbDelayedDeliveryDays_SelectedIndexChanged you need to wrap any code that refers to cmbDelayedDeliveryDays.SelectedItem with a check on
.SelectedIndex
e.g.
If cmbDelayedDeliveryDays.SelectedIndex > 0 Then
     Debug.Print(cmbDelayedDeliveryDays.SelectedValue.ToString())
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 9,061
1 Sergey Alexandrovich Kryukov 8,773
2 Mika Wendelius 7,027
3 Suvendu Shekhar Giri 2,494
4 F-ES Sitecore 2,438


Advertise | Privacy | Mobile
Web03 | 2.8.150728.1 | Last Updated 19 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