• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

Need the first line of a combo box to be blank enterable

I load CboAgency with the code below. How can I enter a blank row before ALLl  so user can enter his/her desireable value?

TheAgenyIdTable = GetAgencyId()
            cboAgencyId.DataSource = TheAgenyIdTable
            cboAgencyId.DataTextField = "AGENCY_Id"
            cboAgencyId.DataValueField = "AGENCY_Id"
            cboAgencyId.DataBind()
            cboAgencyId.Items.Insert(0, New ListItem("--ALL--", ""))
0
sraymond101
Asked:
sraymond101
  • 2
1 Solution
 
bruintjeCommented:
Hello sraymond101,

you could look at
source: http://www.experts-exchange.com/Q_21771251.html
----------
1. include it in the datasource by changing the SQL to inlcude one blank row
2. add it to the datasource as showed in that PAQ > Ds.Tables("mytable").Rows.Add(Ds.Tables("mytable").NewRow)
----------

hope this helps a bit
bruintje
0
 
sraymond101Author Commented:
Adding this line cboAgencyId.Items.Insert(0, New ListItem("", "")) under   cboAgencyId.Items.Insert(0, New ListItem("--ALL--", "")) creates the blanks row but it reads only, and the user can not  enter data there. I would like for the user to be able to start typing into the blank row and the blank is populated with a number from the combo box
0
 
sraymond101Author Commented:
Resolve: My comment above fix it. I just to remove isposback from the cboAgencyId property
0
 
GarylsCommented:
Here is a control that inherits from the combobox. It doesn't add a blank row but will handle a null/empty value. You'll need to bind to "SelectedValueEx".

On press of backspace/delete it will clear the value also.

Hope its some use:

 Public Class TheDropDownList
    Inherits ComboBox

#Region " Windows Form Designer generated code "

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.

    'UserControl overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
      If disposing Then
        If Not (components Is Nothing) Then
          components.Dispose()
        End If
      End If
      MyBase.Dispose(disposing)
    End Sub
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

      Me.SuspendLayout()
      Me.Name = "TheDropDownList"
      Me.Size = New System.Drawing.Size(543, 96)
      Me.ResumeLayout(False)
      Me.PerformLayout()

    End Sub

#End Region

    Const _NullText As String = "-ALL-" ' "(Not Selected)"

    Event SelectedValueExChanged As EventHandler

    Private m_ValueEx As Object
    Property SelectedValueEx() As Object
      Get
        Return m_ValueEx
      End Get
      Set(ByVal value As Object)
        SetSelectedValueEx(value)
      End Set
    End Property

    Private Sub SetSelectedValueEx(ByVal value As Object)
      Static Running As Boolean
      If Running Then Exit Sub
      Try
        Running = True
        If value Is Nothing OrElse value Is DBNull.Value OrElse CStr(value) = "" OrElse CStr(value) = "0" Then
          'Raises the SelectedIndexChanged and SelectedValueChanged events
          Me.SelectedIndex = -1
          Me.Text = _NullText
          m_ValueEx = DBNull.Value
        Else
          m_ValueEx = value
          Me.SelectedValue = m_ValueEx
        End If
        RaiseEvent SelectedValueExChanged(Me, New EventArgs)
      Finally
        Running = False
      End Try
    End Sub

    Private Sub DropDownList_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SelectedValueChanged
      SetSelectedValueEx(Me.SelectedValue)
    End Sub

    Private Sub DropDownList_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        e.Handled = True
        e.SuppressKeyPress = True
        Select Case e.KeyCode
          Case Keys.Delete, Keys.Back
            'Clear the Value
            SetSelectedValueEx(DBNull.Value)
        End Select
    End Sub

    Public Sub New()
      MyBase.New()

      'This call is required by the Windows Form Designer.
      InitializeComponent()

    End Sub
End Class
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now