473,698 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 11927
* 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.DrawMo de'.

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

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
For x As Integer = 0 To 20
ListBox1.Items. Add(String.Form at("Item {0} {1} Line 2", x,
ControlChars.Ne wLine))
Next
ListBox1.DrawMo de = DrawMode.OwnerD rawVariable
End Sub
Private Sub ListBox1_DrawIt em(ByVal sender As Object, ByVal e As
System.Windows. Forms.DrawItemE ventArgs) Handles ListBox1.DrawIt em
Dim g As Graphics = e.Graphics
Dim s As String
Dim d As Date
Dim br As Brush = SystemBrushes.W indowText
Dim brBack As Brush
Dim rDraw As Rectangle
Dim bSelected As Boolean = CBool(e.State And
DrawItemState.S elected)

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

If bSelected Then
brBack = Brushes.LightBl ue
g.FillRectangle (Brushes.LightB lue, 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).T oString
Catch
s = ""
End Try
Debug.WriteLine (String.Format( "{0} {1} {2}", e.Index, s,
e.Bounds.ToStri ng))

g.DrawString(s, ListBox1.Font, Brushes.Black,
RectangleF.op_I mplicit(e.Bound s))
End Sub

Private Sub ListBox1_Measur eItem(ByVal sender As Object, ByVal e As
System.Windows. Forms.MeasureIt emEventArgs) Handles ListBox1.Measur eItem
e.ItemHeight += e.ItemHeight
End Sub

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

"Max" <ma*****@yahoo. com> wrote in message
news:Ne******** ************@co mcast.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.DrawMo de'.


Here's what I found in there:

Private Sub listBox1_DrawIt em(ByVal sender As System.Object, ByVal e As
System.Windows. Forms.DrawItemE ventArgs) Handles ListBox1.DrawIt em
' Set the DrawMode property to draw fixed sized items.
ListBox1.DrawMo de = DrawMode.OwnerD rawFixed
' Draw the background of the ListBox control for each item.
e.DrawBackgroun d()
' 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.Draw String(ListBox1 .Items(e.Index) , e.Font, myBrush, New
RectangleF(e.Bo unds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height ))
' If the ListBox has focus, draw a focus rectangle around the
selected item.
e.DrawFocusRect angle()
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.Measu reString'. 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
18180
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 reserve the spaces for the number if the number of digits are fewer than the number of placeholders. My simplified example: included within a loop such that it displays two columns
7
4031
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 problem is that only the modified data from the SingleLine TextBoxes are returned. The original data are returned for the MultiLine TextBoxes. Also, if the page is sent to the server (for validation, for instance), only the modified data for the...
3
1907
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 click the button to run the code behind. the problem is that when the user presses the ENTER key to insert a new line in the listbox, the button's code behind is executed.
3
13767
by: Sale | last post by:
How can i remove specific line from the multiline textbox?
2
6614
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? Thanks a lot in advance, Pieter
2
2288
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 combobox. Does anybody has any idea how to achieve this? What should I override to draw a multiline-textbox instead oth the default textbox? Thanks a lot in advance,
2
3423
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 enter new, edit existing, and view the names in the array. This all works well, but now I want to be able to select one more names from the list displayed in the multiline textbox then click a button to copy the selected names into another list so...
6
3797
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 = open("filename").read() multilinePattern = "^<tag.... <\/tag>$" re.search(multilinePattern, where, re.MULTILINE)
0
1694
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 display the Text in multiple lines (per entry)? I found some controls on CodeProject but they are to overloaded. I just
0
8671
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8598
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9152
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8856
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6515
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5858
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1997
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.