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

my difficulty dealing with Listbox in VB.net

I am new to VB.net.
I want to display information in some textboxes correspondent to selected item in the listbox. Therefore I have a Sub SelectedIndexChanged as follows:

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
oraconn.ConnectionString = "data source= &db ;uid= &user; pwd = &psd ; unicode=yes"
Dim str2 As String
Try
str2 = "select MA_DVIDCHINH, TEN_DVIDCHINH from ddvi_dchinh" & _
"where ma_DVIDCHINH = '" & _
Me.ListBox1.SelectedValue & "'"
If oraconn.State = ConnectionState.Closed Then
oraconn.Open()
End If
With oracmd
.CommandType = CommandType.Text
.CommandText = str2
.Connection = oraconn
End With
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Dim dr As DataRow
Dim dt As New DataTable
If ds.Tables("IT").Rows.Count > 0 Then
For Each dr In ds.Tables("IT").Rows
Me.TextBox1.Text = dr.Item("TEN_DVIDCHINH")
Me.TextBox3.Text = dr.Item("MA_DVIDCHINH")
Next

End If
Me.TextBox1.Text = sender.text
End Sub
However, in return a runtime error caused by str2 as Me.ListBox1.SelectedValue & is datarowview

How can I do in this case. And do you have any other solutions to bind a listbox with some textboxes.

Thanks in advance.
Oct 26 '07 #1
2 1069
kenobewan
4,871 Expert 4TB
What exactly was the error? Afraid your naming conventions leave a little to be desired :(.
Oct 26 '07 #2
The exception was:"Cast from type 'datarowview' to 'String' is not valid"
That is because Me.ListBox1.SelectedValue does not return a string value.

In my Form_load sub I assigned: Me.ListBox1.DisplayMember = "TEN_DVIDCHINH"
Me.ListBox1.ValueMember = "MA_DVIDCHINH"

So I desire to get data based on the selected valuemember.
Oct 29 '07 #3

Sign in to post your reply or Sign up for a free account.

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...
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...
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...
15
by: nitro_punk85 | last post by:
Hey guys its me again, having trouble with a project for class. We're writing a program to Grade a test, the answer key and student answers r in the same file and we have to read them in and score...
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:
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...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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...
0
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...

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.