473,569 Members | 2,542 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_S electedValueCha nged Event, I have:
_______________ _______________ _______________ _______________ ___
Dim dblVal as Double = Val(ListProdUni ts.SelectedValu e.ToString)
If dblVal > 0 then
dblUnitsConv = dblVal
LabelProdUnits. Text = ListProdUnits.S electedItem.ToS tring

End If
_______________ _______________ _______________ ___________

The variable dblUnitsConv is being set correctly to 3.2 but
LabelProdUnits. Text
shows "System.Data.Da taRowView" 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 2282
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*********@vo daphone.com.au> wrote in message
news:eH******** ******@TK2MSFTN GP12.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.T ext = stDefaultUnit
_______________ _______________ _______

And in the ListProdUnits_S electedValueCha nged Event, I have:
_______________ _______________ _______________ _______________ ___
Dim dblVal as Double = Val(ListProdUni ts.SelectedValu e.ToString)
If dblVal > 0 then
dblUnitsConv = dblVal
LabelProdUnits. Text = ListProdUnits.S electedItem.ToS tring
If the ListBox is databound then SelectedItem returns the current
DataRowView, you can get your text from it using the colname:
LabelProdUnits. Text = ListProdUnits.S electedItem("Un itsProdDescn")

You can also use ListBox.Text since it returns the displaytext of the first
selected item:
LabelProdUnits. Text = ListProdUnits.T ext
--- 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.Ad d( "Text", dtUnits, "UnitsProdDescn " )
HTH,
Greetings


End If
_______________ _______________ _______________ ___________

The variable dblUnitsConv is being set correctly to 3.2 but
LabelProdUnits. Text
shows "System.Data.Da taRowView" 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******** ********@TK2MSF TNGP12.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******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

"Doug Bell" <Po*********@vo daphone.com.au> wrote in message
news:eH******** ******@TK2MSFTN GP12.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.T ext = stDefaultUnit
_______________ _______________ _______

And in the ListProdUnits_S electedValueCha nged Event, I have:
_______________ _______________ _______________ _______________ ___
Dim dblVal as Double = Val(ListProdUni ts.SelectedValu e.ToString)
If dblVal > 0 then
dblUnitsConv = dblVal
LabelProdUnits. Text = ListProdUnits.S electedItem.ToS tring
If the ListBox is databound then SelectedItem returns the current
DataRowView, you can get your text from it using the colname:
LabelProdUnits. Text = ListProdUnits.S electedItem("Un itsProdDescn")

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

first selected item:
LabelProdUnits. Text = ListProdUnits.T ext
--- 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.Ad d( "Text", dtUnits, "UnitsProdDescn " )
HTH,
Greetings


End If
_______________ _______________ _______________ ___________

The variable dblUnitsConv is being set correctly to 3.2 but
LabelProdUnits. Text
shows "System.Data.Da taRowView" 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
3095
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) Me.lboxRP.SetSelected(newRPindex, True) When the last line executes, I get an error message:
3
3599
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 in the subform. Is it possible? How do I do this? Thanks in advance. Paul from Slovakia
8
2872
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 this listbox but I can't for the life of me figure out how to draw the control inside ListBox... I get as far as: private void...
2
2907
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, currently the code is such that with each selection there is a postback. We want to avoid it using filter and javascript. I am not using ADO.NET but adodbc...
6
2863
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 a denormalized mirror of the database, but I'm not having much luck getting the selection logic down (I haven't found a 'hook' where I can access...
1
2259
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 button_click function because the only way to find the listbox is: (listbox)e.item.findcontrol What s the solution to this problem?
7
4522
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 ASP.Net stuff when I need a Windows Form control. I've seen dual listbox populators in countless Windows applications, and have seen them run very...
3
2281
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
4014
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 are not bound, I select from the bottom set and add to the top set which works fine, but now i decide to remove an item from the top set. when i...
5
2837
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 is what the ListBox uses for its display. Correct?
0
7700
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8125
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7676
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7974
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.