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

February 9th, 2005, 05:07 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

February 9th, 2005, 10:13 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

February 10th, 2005, 03:35 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

February 10th, 2005, 05:13 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

February 11th, 2005, 05:19 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

March 1st, 2005, 07:29 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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#.
|
|

June 28th, 2006, 01:15 AM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 20th, 2007, 12:59 AM
|
|
Registered User
|
|
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|
 |