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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

679 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