Solved

combo box vs 2010   not using a label and displaying all text in the box like web site drop down boxes

Posted on 2014-04-10
5
435 Views
Last Modified: 2014-04-14
I want to make my combo box look like how web sites do them
You have all the text within the box and no label

SO you have the box
_______________
! Forward Call to:
___________________

inside to start i want to put Forward call to:

then after the user selects a name from the drop down you get
_____________________
| Forward To: John !
_____________________

When can I adjust the name from the drop down list and reformat it as
drop down list  selection
John
then change it to
Forward to: John
then when its empty
back to
Forward Call To
0
Comment
Question by:john M
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:jayakrishnabh
ID: 39991443
<script>
$(document).ready(function(){
            $("#ddnForward").change(function () {
                if ($(this).val() != "select")
                    $("#label1").text('Forward to: ');
                else
                    $("#label1").text('Forward Call to: ');
            });
        });
</script>

<label id="label1">Forward Call to: </label>
        <select id="ddnForward">
            <option value="select">Select</option>
            <option value="John">John</option>
        </select>
0
 
LVL 3

Author Comment

by:john M
ID: 39991477
Thanks
just so you know this is vb 2010 .net   this is  in a .net application

can you explain your code please and where its  goes
0
 
LVL 5

Accepted Solution

by:
jayakrishnabh earned 500 total points
ID: 39991548
Giving the aspx html page which has the two code pieces in it.

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script>
        $(document).ready(function () {
            $("#ddnForward").change(function () {
                if ($(this).val() != "select")
                    $("#label1").text('Forward to: ');
                else
                    $("#label1").text('Forward Call to: ');
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <label id="label1">Forward Call to: </label>
        <select id="ddnForward">
            <option value="select">Select</option>
            <option value="John">John</option>
        </select>
    </div>
    </form>
</body>
</html>
0
 
LVL 3

Author Comment

by:john M
ID: 39991564
this is not aspx
this is .net programming
    Private Sub cboMDRequestedBy_SelectFriendlyName(ByVal sender As Object, _
                                               ByVal e As System.Windows.Forms.MouseEventArgs) Handles fTransferTo.MouseDown

        'show the Friendly Name
        Me.fTransferTo.DisplayMember = "getFriendlyName"

    End Sub

    'Private Sub ComboBox_Enter_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) _
    'Handles cboMDRequestedBy.KeyDown

    '    ' This moves to the next field when the user press the Enter key just like tabbing.
    '    UtilityClass.ComboBoxEnterKey(sender, e)

    'End Sub

    Private Sub cboRequestedBy_Selected(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles fTransferTo.Leave

        ' declare index variable
        Dim index As Integer
        index = fTransferTo.FindString(fTransferTo.Text)
        If index = -1 Then
            MessageBox.Show(fTransferTo.Text & " is not a DANB Staff member." & vbCrLf & "Please try again", _
            "Invalid Requested By Name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            fTransferTo.Focus()
        Else
            'Get the selected value
            fTransferTo.SelectedIndex = index
            '  display the  Friendly Name
            Me.fTransferTo.DisplayMember = "getFriendlyName"

        End If

    End Sub
    '/////////////////////////////////////////////
    'define the structure for the Requested By combo box
    Protected Structure RequestedByComboBoxItems
        Private FriendlyName As String

        Public Sub New(ByVal FrndlyNm As String)
            FriendlyName = FrndlyNm
        End Sub

        Public ReadOnly Property getFriendlyName() As String
            Get
                Return FriendlyName
            End Get
        End Property
    End Structure
    Private Sub GetMDRequestedByNames()

        Try

            'disable the read only property
            Me.fTransferTo.DropDownStyle = ComboBoxStyle.DropDown

            ' clear the combo datasource
            With Me.fTransferTo
                .DataSource = Nothing
            End With

            Dim FriendlyNameDataReader As SqlDataReader

            ' Get the school names through a data reader
            FriendlyNameDataReader = GetRequestedByUser()
            'bind to an arraylist that contains entries based on the the structure that
            ' has been defined SchoolNumbersComboItems.
            Dim RequestedByComboItems As New ArrayList

            ' add an empty string first
            With RequestedByComboItems
                .Add(New RequestedByComboBoxItems(""))
            End With

            ' add the values from the datareader
            While FriendlyNameDataReader.Read
                With RequestedByComboItems
                    .Add(New RequestedByComboBoxItems(FriendlyNameDataReader.Item("FriendlyName")))
                End With
            End While

            'close the data reader
            FriendlyNameDataReader.Close()

            'bind the arraylist to the combo box 
            With Me.fTransferTo
                .DataSource = RequestedByComboItems
                .DisplayMember = "getFriendlyName"
                .ValueMember = "getFriendlyName"
            End With

        Finally
            ' close the datareader in case it's still open
            If Not (FriendlyNameDataReader Is Nothing) Then
                FriendlyNameDataReader.Close()
            End If

        End Try

    End Sub
]

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39991905
I guess you mean the Prompt Text?

Prompt text is what is shown until user selects a value.

Example here
http://www.aaronlerch.com/blog/2007/12/01/watermarked-edit-controls/

But you want to go a bit further which would require inheriting the combobox and custom painting it.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now