Click here to Skip to main content
15,887,446 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I fill the listbox with tables from SQL base
The colums are b1,b2,b3,b4,b5,b6,b7
There are up to 1 million rows in listbox
example b1,b2,b3,b4,b5,b6,b7 are as follows:
1,2,3,4,5,6,7
4,5,14,25,35,36,39
14,15,22,23,25,30,31
1,7,14,18,22,26,30

If any row contain any of this numbers(1,4,14,23,35,36,37)
that item should given a different color from listbox's forecolor as bellow

1,2,3,4,5,6,7
4,5,14,25,35,36,39
14,15,22,23,25,30,31
1,7,14,18,22,26,30

Thanks for your help?
Posted

I am not sure if it is posible to do this in a listbox unless you implement a custom version of the listbox control. A listbox (as far as I know) cannot distinguish between "subitems" for each item in the list. i.e an item in our case would be each row in the listbox, a subitem would be each number in the row.

If possible by your design, you can replace the listbox with a ListView control that will allow access into SubItem members for each item.

Remember to set the ListView.View property to Details to use this example.

Code below is for C#, but I guess can easily be ported to VB :)

ListView listView = new ListView();

listView.View = View.Details;


ListViewItem lvi = new ListViewItem();

// individual format for each subitem
lvi.UseItemStyleForSubItems = false;

// create and add subitems with unique formats
ListViewItem.ListViewSubItem lviSubItem1 =
    new ListViewItem.ListViewSubItem();
lviSubItem1.Text = "1";
lviSubItem1.ForeColor = Color.Green;

lvi.SubItems.Add(lviSubItemX);
ListViewItem.ListViewSubItem lviSubItem2 =
    new ListViewItem.ListViewSubItem();
lviSubItem2.Text = "2";
lviSubItem2.ForeColor = Color.Red;
lvi.SubItems.Add(lviSubItem2);

ListViewItem.ListViewSubItem lviSubItem3 =
    new ListViewItem.ListViewSubItem();
lviSubItem3.Text = "3";
lviSubItem3.ForeColor = Color.Blue;
lvi.SubItems.Add(lviSubItem3);

// add the subitem to underlying list of items
listView.Items.Add(lvi);


Hope this helps and if not maybe someone will have a way to do it in listbox, but apart from making a custom listbox I can't think of any way to do it :)

Dave
 
Share this answer
 
v2
I think the only way to do this is to come up with a custom control derived from the ListBox control that uses a RichText edit box to display its items.

On the other hand, you could just change the background color of an item than contains one or more of the specified values, and in a tooltip for each item, you could show which of numbers are contained in the list box item.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900