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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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.
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 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…

744 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

12 Experts available now in Live!

Get 1:1 Help Now