Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
460 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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 …
Progress

688 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