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 2269
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
| |