Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 9th, 2005, 05:07 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default To highlight multiple selected values in listbox

Hi,
I have a registration form where i am using a listbox where we can select multiple values.I am storing these values concatenating with commas(for eg. A,B,C).Now i have to update this registration form, so i have to retrieve these values and to hightlight the previously selected values.
I have the idea that first i have to retrieve that field from database and split the commas and then i have to write the code in the front end to display the values.
But in real time i m unable to display in front end.
Can anyone help me.

Thanks and regards
lily



 
Old February 9th, 2005, 10:13 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

Example For Web Application ::

lstChoiceOfCity.Items.FindByValue("1").Selected = true;
lstChoiceOfCity.Items.FindByValue("12").Selected = true;
lstChoiceOfCity.Items.FindByValue("31").Selected = true;

Example for windows application:

lstChoiceOfCity.SetSelected(lstChoiceOfCity.FindSt ringExact("1"),True)
lstChoiceOfCity.SetSelected(lstChoiceOfCity.FindSt ringExact("12"),True)
lstChoiceOfCity.SetSelected(lstChoiceOfCity.FindSt ringExact("31"),True)

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
 
Old February 10th, 2005, 03:35 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This will work to highlight if the values are individually stored, but in my case all the values are stored with commas. Like A,B,C,
I have to highlight only those values not all the values.
What u suggest for this.

 
Old February 10th, 2005, 05:13 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

I guess you can still use this. First split the comma seperated string into an array. Then build a custom logic to highlight the listbox based on this array element.

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
 
Old February 11th, 2005, 05:19 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Of course I can use this, but if I write all these then its highlighting all the list items not only the selected one. I have to hightlight the selected items from the list after retrieving from the database.

 
Old March 1st, 2005, 07:29 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Still i am waiting for reply.Can anyone help me to write the code to hightlight multiple previously selected values in the listbox in C#.

 
Old June 28th, 2006, 01:15 AM
Registered User
 
Join Date: Jun 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Vadivel,

Just follow the code.

private int FindListBoxIndex(ListBox objList, string strData)
{
  ListItem lst = objList.Items.FindByText(strData);
  return objList.Items.IndexOf(lst);
}

if(ds_GetRequest.Tables[0].Rows[0][9].ToString() != "")
{
  string strCon = ds_GetRequest.Tables[0].Rows[0][9].ToString();
  string[] LenOfStr;
  char[] delimiter = {','};
  LenOfStr = strCon.Split(delimiter);
  ListBox.SelectionMode = ListSelectionMode.Multiple ;
  for(int i=0;i<=LenOfStr.Length-2;i++)
   {
    int s = FindListBoxIndex(lstAddl_CLN,LenOfStr[i].ToString());
[s]   ListBox.Items .Selected = true;
     }

}

In these code, the first one is a function, in which you need to pass your drop down control name and the string which you need to find the index. It will give you the selectedindex of the item in the listbox. I got success using this code. Tell me if you face any problem in these. [Hope you have string after spliting, pass the string into the function].

Cordially Yours,

Yuvaraj Ilangovan
 
Old August 20th, 2007, 12:59 AM
Registered User
 
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I tried your code but it did not work for me. I did not understood what ds_GetRequest is. Any way I have the following code to bind the data from a table to listbox. I too know i have use split function. But dont know how to fit that.

 Sub ListLoad()
        ' ||||| DECLARE VARIABLES |||||
        Dim strProducts As String = "select swinstalled from a_desktops where assetcode='" & TextBox1.Text & "'"
        Dim Cmd As New SqlCommand(strProducts, dbconn)
        Dim objReader As SqlDataReader
 Dim objReader As SqlDataReader
        Dim delimStr As String = ","

        Dim delimiter As Char() = delimStr.ToCharArray()
        Dim s As String
        For Each s In strProducts.Split(delimiter)
            Response.Write((s.ToString() + "<br>"))
            Dim Cmd As New SqlCommand(mystring, dbconn)
        Next
        Try
            If dbconn.State = ConnectionState.Closed Then
                dbconn.Open()
            End If
            objReader = Cmd.ExecuteReader(CommandBehavior.CloseConnection)
            lstselectedemployees.Items.Clear()
            lstselectedemployees.DataTextField = "Swinstalled"
            lstselectedemployees.DataSource = objReader
            lstselectedemployees.DataBind()
            objReader.Close()
        Catch ex As Exception
            MsgBox("Error Connecting to Database!", MsgBoxStyle.Critical)
        End Try

    End Sub






Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple Listbox values in another listbox terryv Excel VBA 0 June 27th, 2007 07:01 AM
How to highlight selected dropdown values. sheetm J2EE 0 June 5th, 2007 05:04 AM
Applying Multiple Selected Values to a Listbox rit01 ASP.NET 2.0 Professional 1 December 15th, 2006 07:12 AM
Get selected values from ListBox to DetailsView gerten ASP.NET 2.0 Professional 0 October 12th, 2006 01:21 PM
Listbox Selected values to be displayed on Submit dom1975 C# 0 September 17th, 2005 04:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.