Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 9th, 2005, 04:07 AM
Friend of Wrox
 
Join Date: Jun 2004
Location: Hyderabad, , India.
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



Reply With Quote
  #2 (permalink)  
Old February 9th, 2005, 09:13 AM
Friend of Wrox
 
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
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
Reply With Quote
  #3 (permalink)  
Old February 10th, 2005, 02:35 AM
Friend of Wrox
 
Join Date: Jun 2004
Location: Hyderabad, , India.
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.

Reply With Quote
  #4 (permalink)  
Old February 10th, 2005, 04:13 AM
Friend of Wrox
 
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
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
Reply With Quote
  #5 (permalink)  
Old February 11th, 2005, 04:19 AM
Friend of Wrox
 
Join Date: Jun 2004
Location: Hyderabad, , India.
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.

Reply With Quote
  #6 (permalink)  
Old March 1st, 2005, 06:29 AM
Friend of Wrox
 
Join Date: Jun 2004
Location: Hyderabad, , India.
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#.

Reply With Quote
  #7 (permalink)  
Old June 28th, 2006, 01:15 AM
Registered User
 
Join Date: Jun 2006
Location: Bangalore, Karnataka, India.
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
Reply With Quote
  #8 (permalink)  
Old August 20th, 2007, 12:59 AM
Registered User
 
Join Date: Aug 2007
Location: , , .
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

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 06: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



All times are GMT -4. The time now is 12:46 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.