how to change the background color of an item in a listbox when its string value is equal to something? - vb.net

i have a listbox that contains the words "week1", "week2", ..... all the way up to "week52" and when i select a week from the listbox it will retrieve a value from a mysql database that will represent a progress bar value. my progress bar has a range of 0-120 and i would like to have all the weeks that have values higher than 100 to be highlighted or marked somehow, in the listbox. so my question is, "is there a way to set the background color of certain weeks in the listbox to orange based on the value that they represent on the database?
for example for "week1", the value is 114, so when the listbox loads, i want the background color of the item "week1" in the list to be orange (indicating that it's current value is higher than 100)? i know that this requires me to implement a user defined drawing function for the listbox items but i dont know where i would even start. i would like this to be somewhat automatic so that it checks the values and changes the background colors of any value higher than 100, instead of me specifying a name of the item.
Thanks in advance!

I don't believe you can do this with a Listbox (at least not without creating your own implementation/subclassing/overriding/whatever of a Listbox).
Pretty sure you could do it with a ListView (in Detail mode), though, if that helps.

Related

listbox sorting issue when in ownerdrawfixed mode

I have a listbox with the sorted property set to true. When the drawmode is set to normal, it sorts as expected, in alphabetical order. But, when I have the drawmode set to ownerdrawfixed so that I can change the color of certain items, then the sorted order is quite different. It is not as if the sorted property is set to false (which would list the items in the order added to the list), but I have not figured out what order it is using. The item class used to change the color only has 2 properties: the text (as string), and the color... with the text being the first property. Each time I run the program, the list is the same, so it's not random. But it definitely is not alphabetical. I have no code to post since I set the sorted property at design time, there's nothing that would change this in the code.
I am including a screen shot with 4 Listboxes, which should show what is happening.
Sorting Issue
I have searched for listbox sorting issues, to which only 2 posts show, neither of which addresses this issue.
I have found a work-around, but I do not believe this should be necessary, and it is extra processing and overhead that I feel there should not need to be.
I have tried feeding the data into a sorted, drawmode normal, non-visible listbox, and then read this 1 item at a time and feed it into a non-sorted, drawmode ownerdrawfixed listbox so that I can change the color of some items. While this does work, it could eventually slow the program down if there are very many items to be read. And, I have figured out what order it is putting them in if I use a sorted ownerdrawfixed box to begin with. it is putting the first 2 items at the bottom of the list, then alternates top-bottom... so the order would be something like this.... 3, 5, 7, 9, 10, 8, 6, 4, 2, 1. I saw this when I first tried reading the sorted normal list and feeding it into the sorted ownerdrawfixed list to see where it was putting things in regards to order entered.

Excel VBA mulitiple checkboxes

is it possible to create listbox with multiple checkboxes in one row (Excel VBA)?
Thanks
Kamil
I'm not sure I understood your question fully, but I'll elaborate on ListBoxes as much as I can.
First things first: Checkboxes and ListBoxes are different objects in Excel Userforms. The first is the little box that returns a "true/false". The second is a list of items which can be chosen. Clicking in a Checkbox will make the tick mark appear/disappear (or fade if tristate is enabled), while clicking a Listbox row will turn the listbox row "blue"/"white" (or whatever color is being used for the selected rows). In both elements, clicking is a way to toggle between True and False.
While a checkbox only allows for a single information to be marked as True or False, a Listbox allows you to select entries out of a list. That list may be inserted through code (.AddItem method) or passed from a range (.RowSource property)
ListBox objects allow for multiple columns of data to be attributed to one row element, but each row is an entire element (which means you cannot pick the element on row 3, column 2 - only all of row 3). The number of columns is established using the ColumnCount property.
By changing the value of the MultiSelect property, you'll allow the user to select multiple or single row elements simultaneously on your Listbox. Using the Selected( RowIndex ) property, you can check whether or not an item is currently selected (returns True/False). Remember that row indexes start at 0.
Finally, if you're using the MultiSelect property set to fmMultiSelectSingle and have a single column (as far as I know), the Text property can be used to return the selected item's value.
An easy example of a listbox is in Excel can be found at File > Options > Customize Ribbon (or something like that). There are two listboxes, one (on the left) with the visible items and another with the available items. A pair of command buttons is used to move items between boxes. That's a simple application you can likely find already setup online.
Am I on track to answer your question?

Items should be arrange into three columns in CheckedListBox or listview or listbox

I have used CheckedListBox control in vb.net application.
I have several items as follow, item 1, item 2, item 3........item 100.
Now, i want all these items to arrange into three columns and then appear verticle scrollbar.
But, in CheckedListBox, it appears as horizontally. i want it to appear horizontally for just three columns and then vertical scroll should enable.
Can you please suggest if possible in CheckedListBox control or any other control and if possible then how i would have to set its property to achieve this.
I don't think you can do that in a CheckedListBox....
You could create a FlowLayoutPanel, with a fixed width and add AutoScroll = True.
Then add a number of CheckBox controls to it.
You could have problems regarding column alignment and margins. If that's the case, you can set the checkbox Autosize = False and make them a little larger (in order to contain the text)
Or you can reduce the Height of the checkboxes to reduce spaces (is this what you want?)
eg. Height = 15
Use repeat direction =horizontal and repeat column =3 for checkbox list

Want to change foreColor of some of the items in a ListBox

I am developing an attendance count system, where all the registered student in a class are shown in a listbox. But I want to show name of the students who are currently present in a may be GREEN color, and all other students in RED color by default. I can get the index of a each items but controlling only some of the items seems difficult to me.
say list is looking this way,
Ataur
Warda
Bappy
Devid
Lina
now only ataur and bappy are present, [ I received a string data from my hardware that confirms that they are in present ] from the database I can get the their id and from the listBox i can get the index as well. Now how do I change the forColor of only these two not others?
Pardon me if my question seems silly, I am very new at VB.net
You cannot do that by default with windows forms.
You have to draw your own list box item.
http://www.codeguru.com/forum/archive/index.php/t-301047.html

choosing the right control for developing windows application

I am looking for a contol either listbox or listview to support my requirements.
Basically how my application looks is:
alt text http://img51.imageshack.us/img51/451/39967846.png
The background should be black
when the user clicks any 'row' the
row should get highlighted witgh
grey.
The user will have the ability to
search items in this control.
For example , if one of the row
displays 'This is the second Item in
this car'
If the user searches for Car, that corresponding row(s)
should get
highlighted with pink.
The user should be able to search an item in this contol and specify a number to display the lines below the searched row.
For example, if the user Searched for 'car' 5, the rows that have car should get highlighted and their immediate 5 rows.
I mean
Search Result :
car row
next row 1
next row 2
next row 3
next row 4
next row 5
car row
next row 1
next row 2
next row 3
next row 4
next row 5
The user
should be able to drag and drop the
files and they should get opened in
this 'control' i.e each row should
display a new line till the EOF.
The user
will have the ability to right click
on the row, context menu pops up
displaying that row item.
The contol
should be able to display specific
text items in a row(s) with
different color.
Having said these things. I used to program in VC++6, VB6. But using those version now seems not realistic now as I lost touch. But if I have to use the latest 2008 versions, for which I do not have any experience seems scary.
So, If you are reading this , and you have got some experience in these fields or using controls that support my requirement, can you please let me know which programming language or IDE and Control should I use to develop this application.
PS: the image is made using mspaint and does not represent actual program.
As for language I would suggest either C# or VB.Net. They are both great languages and there is tons of support on the Internet for them. Just pick the one you are most comfortable with. As for a control that does what you are asking,
As for the control, it really depends on what platform you target. I have very little experience with WPF so can't help you with that. However, if you want to use WinForms, I would suggest the ListView control. It provides a lot of flexibility in terms of how you can use it. You will need to write the code to identify the rows and highlight them, but that shouldn't be too difficult once you understand how the ListView works.
Here are a couple tips if you do use ListView:
Set ListView.View to Details (this provides you with a grid-like control)
Set ListView.HideSelection to false
Set ListView.FullRowSelect to true
Set ListView.BackColor to Black
Set ListView.ForeColor to White
You can hide the column headers by setting ListView.HeaderStyle to None
If you want to support selecting multiple rows, you can set ListView.MultiSelect to true
To highlight row, set the ListViewItem.BackColor and ForeColor
The big let down of this control is that you don't have much control over the color of selected rows. There are techniques out there to control this, but it's not a simple property set. If you are interested, I think this question/answer might help.