Click here to Skip to main content
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 6: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 8,963
1 OriginalGriff 6,726
2 Peter Leow 4,232
3 Zoltán Zörgő 3,769
4 Richard MacCutchan 2,558

Advertise | Privacy | Mobile
Web04 | 2.8.150123.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