473,385 Members | 1,834 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,385 software developers and data experts.

ListBox

Hi,
I thought that this would be a simple exercise but I am struggling to get a
result.
I need a listbox that will display a list of items from a DataTable,
dtUnits. The displayed list comes from Column [UnitsProdDescn]. Selecting an
item in this list needs to return a value from Column [UnitsConvn].

Data in dtUnits is
UnitsProdDescn UnitsConvn
Carton 3.2
Case*** 0

So in the Form Load Sub I have:
_____________________________________________
stDefaultUnits= "Carton"
dblUnitsConv = 1.0
With ListProdUnits
.DataSource = dtUnits
.DisplayMember = "UnitsProdDescn"
.ValueMember = "UnitsConvn"
.SelectedValue = stDefaultUnit

End With
_____________________________________

And in the ListProdUnits_SelectedValueChanged Event, I have:
__________________________________________________ _____________
Dim dblVal as Double = Val(ListProdUnits.SelectedValue.ToString)
If dblVal > 0 then
dblUnitsConv = dblVal
LabelProdUnits.Text = ListProdUnits.SelectedItem.ToString

End If
__________________________________________________ ______

The variable dblUnitsConv is being set correctly to 3.2 but
LabelProdUnits.Text
shows "System.Data.DataRowView" instead of "Carton"

Also the list shows Case*** as the selected row which should be Carton.

Can someone tell me what I am doing wrong?

Doug


Nov 21 '05 #1
5 2268
Doug,

Mostly are this kind of errors by a misspelling of the datacolumnname

Are you sure that this is right,
..ValueMember = "UnitsConvn"
(It has real to be case sensitive right).

Not that it can be the error, however why don't you use not as normally the
selected index change event?

I hope this helps.

Cor
Nov 21 '05 #2
Hi,

"Doug Bell" <Po*********@vodaphone.com.au> wrote in message
news:eH**************@TK2MSFTNGP12.phx.gbl...
Hi,
I thought that this would be a simple exercise but I am struggling to get
a
result.
I need a listbox that will display a list of items from a DataTable,
dtUnits. The displayed list comes from Column [UnitsProdDescn]. Selecting
an
item in this list needs to return a value from Column [UnitsConvn].

Data in dtUnits is
UnitsProdDescn UnitsConvn
Carton 3.2
Case*** 0

So in the Form Load Sub I have:
_____________________________________________
stDefaultUnits= "Carton"
dblUnitsConv = 1.0
With ListProdUnits
.DataSource = dtUnits
.DisplayMember = "UnitsProdDescn"
.ValueMember = "UnitsConvn"
.SelectedValue = stDefaultUnit
End With
stDefaultUnit ( "Carton" ) is displaytext not a value, so you can't assign
that to SelectedValue. You can assign it to the .Text property which will
find and select the item with that text:

ListProdUnits.Text = stDefaultUnit
_____________________________________

And in the ListProdUnits_SelectedValueChanged Event, I have:
__________________________________________________ _____________
Dim dblVal as Double = Val(ListProdUnits.SelectedValue.ToString)
If dblVal > 0 then
dblUnitsConv = dblVal
LabelProdUnits.Text = ListProdUnits.SelectedItem.ToString
If the ListBox is databound then SelectedItem returns the current
DataRowView, you can get your text from it using the colname:
LabelProdUnits.Text = ListProdUnits.SelectedItem("UnitsProdDescn")

You can also use ListBox.Text since it returns the displaytext of the first
selected item:
LabelProdUnits.Text = ListProdUnits.Text
--- Or you can databind the label the same way as the listbox, then it will
show the text of the selected item without the need to handle any events:
LabelProdUnits.DataBindings.Add( "Text", dtUnits, "UnitsProdDescn" )
HTH,
Greetings


End If
__________________________________________________ ______

The variable dblUnitsConv is being set correctly to 3.2 but
LabelProdUnits.Text
shows "System.Data.DataRowView" instead of "Carton"

Also the list shows Case*** as the selected row which should be Carton.

Can someone tell me what I am doing wrong?

Doug

Nov 21 '05 #3
Cor,
Thanks, the name is spelt correctly. When I misspell it (eg wrong case), I
get a different error I get a different error, to do with the member not
being able to be set.

Are you indicating that the coding method looks correct?

Doug

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Doug,

Mostly are this kind of errors by a misspelling of the datacolumnname

Are you sure that this is right,
.ValueMember = "UnitsConvn"
(It has real to be case sensitive right).

Not that it can be the error, however why don't you use not as normally the selected index change event?

I hope this helps.

Cor

Nov 21 '05 #4
Hi Bart,

Thank you.
Setting the ListBox.Text value solved one problem
and setting the TextBox.Text = ListBox.Text solved the other.

I was surprised that the Text property is not displayed in the intelisense
list.

Doug
"Bart Mermuys" <bm*************@hotmail.com> wrote in message
news:eW**************@TK2MSFTNGP10.phx.gbl...
Hi,

"Doug Bell" <Po*********@vodaphone.com.au> wrote in message
news:eH**************@TK2MSFTNGP12.phx.gbl...
Hi,
I thought that this would be a simple exercise but I am struggling to get a
result.
I need a listbox that will display a list of items from a DataTable,
dtUnits. The displayed list comes from Column [UnitsProdDescn]. Selecting an
item in this list needs to return a value from Column [UnitsConvn].

Data in dtUnits is
UnitsProdDescn UnitsConvn
Carton 3.2
Case*** 0

So in the Form Load Sub I have:
_____________________________________________
stDefaultUnits= "Carton"
dblUnitsConv = 1.0
With ListProdUnits
.DataSource = dtUnits
.DisplayMember = "UnitsProdDescn"
.ValueMember = "UnitsConvn"
.SelectedValue = stDefaultUnit
End With
stDefaultUnit ( "Carton" ) is displaytext not a value, so you can't assign
that to SelectedValue. You can assign it to the .Text property which

will find and select the item with that text:

ListProdUnits.Text = stDefaultUnit
_____________________________________

And in the ListProdUnits_SelectedValueChanged Event, I have:
__________________________________________________ _____________
Dim dblVal as Double = Val(ListProdUnits.SelectedValue.ToString)
If dblVal > 0 then
dblUnitsConv = dblVal
LabelProdUnits.Text = ListProdUnits.SelectedItem.ToString
If the ListBox is databound then SelectedItem returns the current
DataRowView, you can get your text from it using the colname:
LabelProdUnits.Text = ListProdUnits.SelectedItem("UnitsProdDescn")

You can also use ListBox.Text since it returns the displaytext of the

first selected item:
LabelProdUnits.Text = ListProdUnits.Text
--- Or you can databind the label the same way as the listbox, then it will show the text of the selected item without the need to handle any events:
LabelProdUnits.DataBindings.Add( "Text", dtUnits, "UnitsProdDescn" )
HTH,
Greetings


End If
__________________________________________________ ______

The variable dblUnitsConv is being set correctly to 3.2 but
LabelProdUnits.Text
shows "System.Data.DataRowView" instead of "Carton"

Also the list shows Case*** as the selected row which should be Carton.

Can someone tell me what I am doing wrong?

Doug


Nov 21 '05 #5
Doug,

Just a kind of code blindness what was for me yesterday evening.

:-)

Cor
Nov 21 '05 #6

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

Similar topics

17
by: amber | last post by:
Hello. Can someone tell me what I may be doing wrong here? I'm using the code (lboxRP is a listbox): Dim newRPindex As Integer newRPindex = Me.lboxRP.FindString(RP)...
3
by: Paul T. Rong | last post by:
I have a listbox (of product names) control on my form. I want to pass the selected item (a product name) to a subform, and the product unitprice should apear automatically next to the product name...
8
by: Oddball | last post by:
Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler. What I want to draw as the item is another control. I have created a user control that I would like to list in...
2
by: collie | last post by:
Hi, I have 2 listboxes. The first gets populated from the db as soon as the page loads. The second listbox get populated based on the user's selection from the first listbox. However,...
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
1
by: yamne | last post by:
I have a problem. When I click in edit datagrid button I show two listbox and two button. I use two button to move data between two listbox. My problem is that I can't call the listbox in the...
7
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but...
3
by: Ali Chambers | last post by:
Hi, I have created a listbox called "dtlist1" on my VB.NET form. I call a procedure as follows: Private Sub openfile(flname As String) dtlist1.Items.Clear() etc..
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
5
by: Academia | last post by:
(If you've seen this in the drawing NG, sorry. I inadvertently sent it there.) I have a listbox populated with Objects. The Class has a String field that ToString returns. I assume that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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,...
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...

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.