About the listbox control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, All,
I'm using MS.net 2003 and using a windows.forms.listbox control for my
window application but I don't know why the Horizontal Scrollbar could NOT be
shown even if I set HorizontalScrollbar = true. The text info in listbox
already beyond its right edge. How can I see the hidden part info in listbox?

here is a part of codes.

ListBox.ValueMember = XX
ListBox.DisplayMember = XXXX
ListBox.DataSource = objTarget

Is this because I'm using dataSource and displayMember?

Thanks for your help and have a good one

Brian
 
Hi Brian,

It is a little unclear to me what your problem is.
Is the horizontal scrollbar missing, even if you have set HorizontalScrollbar = true?
If so, I am unable to reproduce this problem as for me the scrollbar is showing when a listbox item is wider than the listbox. Also using MS.Net 2003. Tested using a datasource.

If the problem persists, try using a tooltip showing the full line.
 
Morten, Thank you
Is the horizontal scrollbar missing, even if you have set HorizontalScrollbar = true?

Yes, horizontal scrollbar never be show even if I have set
HorizontalScrollbar = true ( and listbox item is wider than the listbox.) I
don't know why. If I set ScrollAlwaysVisible = true, it still won't work.
it's stronge.

Thanks and have a good day

Brain
 
Morten,
You told me you tested using a datasource is OK, how did you do that?
If I use ListBox1.Items.Add(" Item is a very large value that requires
scroll bars"), the Horizontal scroll bar works fine. but If I use
ListBox1.ValueMember = "ID"
ListBox1.DataSource = ObjTarge ' this is a collection object
ListBox1.DisplayMember = "Display" ' this is a proprty of the object

the Horizontal scroll bar won't work. Did I miss something?

BTW, .net 2003, this is not tooltip property for listbox. but In VB.6,
listbox has tooltip property. I'm using .Net 2003

Thanks

Brian
 
Simple DataSource using an ArrayList

ArrayList list = new ArrayList();
list.Add("Hello World, this is a very long line!");

listBox1.DataSource = list;

A more complex DataSource using a DataSet

DataSet ds = new DataSet("MyDataSet");
ds.Tables.Add("MyDataTable");
ds.Tables["MyDataTable"].Columns.Add("MyColumn");
ds.Tables["MyDataTable"].Rows.Add(new object[]{"Hello World, this is a very long line!"});

listBox1.DataSource = ds.Tables["MyDataTable"];
listBox1.DisplayMember = "MyColumn";

As for tooltip. Add a ToolTip to your project. A ToolTip property should then be added at the bottom of the ListBox properties.

You probably need to set it manually based on which item the cursor is currently over, something like

toolTip1.SetToolTip(listBox1, ds.Tables[0].Rows[0][0].ToString());
 
In C# code I've written using the System.Windows.Forms.ListBox, if the
ListBox.HorizontalExtent property isn't explicitly set to something greater
than zero then your listbox won't display the horizontal scroll bar.
 
Back
Top