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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

808 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