Click here to Skip to main content
12,698,330 members (23,279 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB 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 6:18am
vidkaat570

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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2017
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