Click here to Skip to main content
11,710,943 members (88,358 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET

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
       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
        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.

Posted 19-Feb-13 5:18am

1 solution

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

Solution 1

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
If cmbDelayedDeliveryDays.SelectedIndex > 0 Then
End If

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 549
1 OriginalGriff 255
2 Peter Leow 134
3 Abhinav S 130
4 Richard MacCutchan 90
0 Abhinav S 60
1 Member 4653839 40
2 barneyman 35
3 Sergey Alexandrovich Kryukov 35
4 Member 11793820 35

Advertise | Privacy | Mobile
Web01 | 2.8.150819.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