473,414 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Multiline Listbox?

Max
I need some control that basically acts as a listbox, but allows each
item to take up more then one line. I've tried adding a new item and
putting in a vbCrLf in there, but that just comes out as a box on the
same line. Is there some way of making the listbox show multiple lines
for each item, or is there another control (3rd party maybe) that will
let me do this?
Nov 20 '05 #1
6 11882
* Max <ma*****@yahoo.com> scripsit:
I need some control that basically acts as a listbox, but allows each
item to take up more then one line. I've tried adding a new item and
putting in a vbCrLf in there, but that just comes out as a box on the
same line. Is there some way of making the listbox show multiple lines
for each item, or is there another control (3rd party maybe) that will
let me do this?


You will have to draw the items yourself. Have a look at the listbox's
'DrawMode' property.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
Max
Herfried K. Wagner [MVP] wrote:
* Max <ma*****@yahoo.com> scripsit:

I need some control that basically acts as a listbox, but allows each
item to take up more then one line. I've tried adding a new item and
putting in a vbCrLf in there, but that just comes out as a box on the
same line. Is there some way of making the listbox show multiple lines
for each item, or is there another control (3rd party maybe) that will
let me do this?


You will have to draw the items yourself. Have a look at the listbox's
'DrawMode' property.


Never used that property before, how does it work?
Nov 20 '05 #3
* Max <ma*****@yahoo.com> scripsit:
I need some control that basically acts as a listbox, but allows each
item to take up more then one line. I've tried adding a new item and
putting in a vbCrLf in there, but that just comes out as a box on the
same line. Is there some way of making the listbox show multiple lines
for each item, or is there another control (3rd party maybe) that will
let me do this?


You will have to draw the items yourself. Have a look at the listbox's
'DrawMode' property.


Never used that property before, how does it work?


There is a basic sample in the documentation for 'ListBox.DrawMode'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
Hi,

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
For x As Integer = 0 To 20
ListBox1.Items.Add(String.Format("Item {0} {1} Line 2", x,
ControlChars.NewLine))
Next
ListBox1.DrawMode = DrawMode.OwnerDrawVariable
End Sub
Private Sub ListBox1_DrawItem(ByVal sender As Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
Dim g As Graphics = e.Graphics
Dim s As String
Dim d As Date
Dim br As Brush = SystemBrushes.WindowText
Dim brBack As Brush
Dim rDraw As Rectangle
Dim bSelected As Boolean = CBool(e.State And
DrawItemState.Selected)

rDraw = e.Bounds
rDraw.Inflate(-1, -1)

If bSelected Then
brBack = Brushes.LightBlue
g.FillRectangle(Brushes.LightBlue, rDraw)
g.DrawRectangle(Pens.Blue, rDraw)
Else
brBack = Brushes.White
g.FillRectangle(brBack, e.Bounds)
End If

br = Nothing
brBack = Nothing
rDraw = Nothing
Try
s = ListBox1.Items.Item(e.Index).ToString
Catch
s = ""
End Try
Debug.WriteLine(String.Format("{0} {1} {2}", e.Index, s,
e.Bounds.ToString))

g.DrawString(s, ListBox1.Font, Brushes.Black,
RectangleF.op_Implicit(e.Bounds))
End Sub

Private Sub ListBox1_MeasureItem(ByVal sender As Object, ByVal e As
System.Windows.Forms.MeasureItemEventArgs) Handles ListBox1.MeasureItem
e.ItemHeight += e.ItemHeight
End Sub

Ken
-------------

"Max" <ma*****@yahoo.com> wrote in message
news:Ne********************@comcast.com:
I need some control that basically acts as a listbox, but allows each
item to take up more then one line. I've tried adding a new item and
putting in a vbCrLf in there, but that just comes out as a box on the
same line. Is there some way of making the listbox show multiple lines
for each item, or is there another control (3rd party maybe) that will
let me do this?


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 262.10.6 - Release Date: 5/28/2004
Nov 20 '05 #5
Max
Herfried K. Wagner [MVP] wrote:
* Max <ma*****@yahoo.com> scripsit:

I need some control that basically acts as a listbox, but allows each
item to take up more then one line. I've tried adding a new item and
putting in a vbCrLf in there, but that just comes out as a box on the
same line. Is there some way of making the listbox show multiple lines
for each item, or is there another control (3rd party maybe) that will
let me do this?
You will have to draw the items yourself. Have a look at the listbox's
'DrawMode' property.

Never used that property before, how does it work?


There is a basic sample in the documentation for 'ListBox.DrawMode'.


Here's what I found in there:

Private Sub listBox1_DrawItem(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
' Set the DrawMode property to draw fixed sized items.
ListBox1.DrawMode = DrawMode.OwnerDrawFixed
' Draw the background of the ListBox control for each item.
e.DrawBackground()
' Create a new Brush and initialize to a Black colored brush by default.
Dim myBrush As Brush

' Determine the color of the brush to draw each item based on the
index of the item to draw.
Select Case (e.Index)
Case 0
myBrush = Brushes.Red
Case 1
myBrush = Brushes.Orange
Case 2
myBrush = Brushes.Purple
End Select

' Draw the current item text based on the current Font and the custom
brush settings.
e.Graphics.DrawString(ListBox1.Items(e.Index), e.Font, myBrush, New
RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
' If the ListBox has focus, draw a focus rectangle around the
selected item.
e.DrawFocusRectangle()
End Sub

So I get how that works, I just use listBox1.items.add("Some text") and
the first time it paints the text red... But this still doens't help me
in making the thing work on multiple lines. Or am I missing something???
Nov 20 '05 #6
* Max <ma*****@yahoo.com> scripsit:
So I get how that works, I just use listBox1.items.add("Some text")
and the first time it paints the text red... But this still doens't
help me in making the thing work on multiple lines. Or am I missing
something???


In the listbox's 'MeasureItem' event, measure the string to be drawn for
an item using 'Graphics.MeasureString'. In the 'DrawItem' event, the
string is drawn using 'DrawString'. Always have a look at the 'e'
parameters of the event handlers.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Rookie | last post by:
I need to display several columns of numbers in a textbox. I wish to display the columns with the decimal point position aligned vertically. I have found that the # digit placeholders do not...
7
by: Joel Finkel | last post by:
Folks, I have a form that has several TextBoxes, some of which have the TextMode set to MultiLine. Each is pre-loaded with data from a database. The user is allowed to modify each entry. The...
3
by: Antonio Lopez Arredondo | last post by:
hi all again..... I have an ASP.NET application that has a multiline textbox and a single button. the user should be able to write inside the many paragraphs in the multiline textbox and then...
3
by: Sale | last post by:
How can i remove specific line from the multiline textbox?
2
by: Pieter | last post by:
Hi, I'm looking for a multiline combobox. The only way I found was this one: http://www.vbcity.com/forums/faq.asp?fid=15&cat=ListBox%2FComboBox#TID58434 Does anybody has any other suggestions?...
2
by: Pieter | last post by:
Hi, Using this Multiline Combobox(http://www.vbcity.com/forums/faq.asp?fid=15&cat=ListBox%2FComboBox#TID58434), doesn't allow the user to type multi line text in the texbox-part of the...
2
by: Mike | last post by:
I am trying to write a little program for my own use using VB2005 express edition. I have a list of peoples names in a file that I read into an array of strings. I am using a multiline textbox to...
6
by: Zdenek Maxa | last post by:
Hi all, I would like to perform regular expression replace (e.g. removing everything from within tags in a XML file) with multiple-line pattern. How can I do this? where =...
0
by: Stefan P. | last post by:
Hi everyody, I want to diplay strings of some objects in a LixtBox. Sometimes the text is longer than my ListBox and a horizontal scrollbar is displayed. Is it possible to get the ListBox to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.