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 5 2267
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
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
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
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
Doug,
Just a kind of code blindness what was for me yesterday evening.
:-)
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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)...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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..
|
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...
|
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...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |