By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,659 Members | 940 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,659 IT Pros & Developers. It's quick & easy.

ListBox

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
Doug,

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

:-)

Cor
Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.