ListBox Question
-
Hi everyone, I have a listbox derived from a table with the following record: Listbox_answer_item Bleu Red Black this is from an answer table base on a particular question. since a question can have more than one asnwer, I like to number the response to a question I rather show the items in the list box in sequential manner with a numbering system. For example: Listbox_answer_item 1. Bleu (first answer) 2. Red (second answer) 3. Black (third answer) 4. etc.. this number should be a position number..which answer that enters first and so forth.. Thanks in advance!
-
Hi everyone, I have a listbox derived from a table with the following record: Listbox_answer_item Bleu Red Black this is from an answer table base on a particular question. since a question can have more than one asnwer, I like to number the response to a question I rather show the items in the list box in sequential manner with a numbering system. For example: Listbox_answer_item 1. Bleu (first answer) 2. Red (second answer) 3. Black (third answer) 4. etc.. this number should be a position number..which answer that enters first and so forth.. Thanks in advance!
I think this is what you are asking for VB.Net
Dim answers() As String = { "Bleu", "Red", "Black" }
For I As Integer = 0 To answers.Length - 1
ListBox1.Items.Add((I + 1).ToString() + ". " + answers(I))
NextVB6
Dim I As Integer
Dim answers(2) As Stringanswers(0) = "Bleu"
answers(1) = "Red"
answers(2) = "Black"For I = 0 To UBound(answers)
List1.AddItem CStr(I + 1) + ". " + answers(I)
Next ITo add more answers to the listbox, just add more elements to the array.
-
I think this is what you are asking for VB.Net
Dim answers() As String = { "Bleu", "Red", "Black" }
For I As Integer = 0 To answers.Length - 1
ListBox1.Items.Add((I + 1).ToString() + ". " + answers(I))
NextVB6
Dim I As Integer
Dim answers(2) As Stringanswers(0) = "Bleu"
answers(1) = "Red"
answers(2) = "Black"For I = 0 To UBound(answers)
List1.AddItem CStr(I + 1) + ". " + answers(I)
Next ITo add more answers to the listbox, just add more elements to the array.
Hi, Thanks for replying. these answers are from a Question_Answer table relationship. The listbox is binding with Qestion_Answer table based on Question_PK and Answer_PK. so the answer is not hardcoded. I want to enumarate the answers on the listbox. Thanks again. PS. vb.net and sql
-
Hi everyone, I have a listbox derived from a table with the following record: Listbox_answer_item Bleu Red Black this is from an answer table base on a particular question. since a question can have more than one asnwer, I like to number the response to a question I rather show the items in the list box in sequential manner with a numbering system. For example: Listbox_answer_item 1. Bleu (first answer) 2. Red (second answer) 3. Black (third answer) 4. etc.. this number should be a position number..which answer that enters first and so forth.. Thanks in advance!
You should be able to use the ListBox Format event to solve this problem. Some rough and ready code showing the general idea
Private data As String() = {"One", "Two", "Three", "Four"}
Public Sub New()
InitializeComponent()
addhandler listBox1.format, addressof listBox1_Format
listBox1.DataSource = data
End SubPrivate Sub listBox1_Format(sender As Object, e As ListControlConvertEventArgs)
Dim list As IList = DirectCast(DirectCast(sender, ListBox).DataSource, IList)
Dim idx As Int32 = list.IndexOf(e.ListItem)
' format as "1. One", "2. Two" etc
e.Value = String.Format("{0}. {1}", idx + 1, e.ListItem)
End SubAlan.
modified on Friday, June 17, 2011 10:37 AM
-
You should be able to use the ListBox Format event to solve this problem. Some rough and ready code showing the general idea
Private data As String() = {"One", "Two", "Three", "Four"}
Public Sub New()
InitializeComponent()
addhandler listBox1.format, addressof listBox1_Format
listBox1.DataSource = data
End SubPrivate Sub listBox1_Format(sender As Object, e As ListControlConvertEventArgs)
Dim list As IList = DirectCast(DirectCast(sender, ListBox).DataSource, IList)
Dim idx As Int32 = list.IndexOf(e.ListItem)
' format as "1. One", "2. Two" etc
e.Value = String.Format("{0}. {1}", idx + 1, e.ListItem)
End SubAlan.
modified on Friday, June 17, 2011 10:37 AM
you've got some c# in your text there
listBox1.Format += New ListControlConvertEventHandler(listBox1_Format)
should be
addhandler listbox1.format, addressof listbox1_format
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
-
you've got some c# in your text there
listBox1.Format += New ListControlConvertEventHandler(listBox1_Format)
should be
addhandler listbox1.format, addressof listbox1_format
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
-
Good catch, I'd put C# source through a code converter and must have copied that line in separately. Alan.
No the converters don't handle the event handlers properly on conversion.
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch