Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pull valuemember from listbox & assign to variable 1

Status
Not open for further replies.

sam225

Programmer
Nov 13, 2001
7
CA
Hey

New to VB.NET. Linked listbox to a table in sqlserver. When the user clicks on an item I am trying to pull the valuemember associated with the record in the dataset and assign it a variable so I can use this as criteria in a search. Keep getting error about can't cast DataRowView to an integer. It doesn't like integer or string variables. Here's my code. Help. Thanks in advance.


strClientCode = (lstClient.ItemslstClient.DisplayMember)


 
Hi,
Me again. Tried this as well and get
Cast from type 'DataRowView' to type 'String' is not valid.
&
Cast from type 'DataRowView' to type 'Integer' is not valid

strclientcode = lstClient.Items(lstClient.SelectedIndex)
intClientcode = lstClient.Items(lstClient.SelectedIndex)

 
Hi
Me again. Tried this and got

Index 1 is not non-negative & below total rows count


Dim i As Integer, strClientCode As String, intClientcode As Integer
Dim selected(lstClient.SelectedIndices.Count - 1) As Integer
lstClient.SelectedIndices.CopyTo(selected, 0)

For i = 0 To selected.Length - 1
Dim index As Integer = selected(i)
Dim item As Object = lstClient.Items(index)
Dim strInstClient As String = CType(dvInstrClient(index)("Client_Code"), String)

Next i

Not sure what I am doing...Help Thx
 
Sam225 - Please post your results, we are trying to do the same and are getting nowhere.
 
Sam225 - Please post your solution to:
"When the user clicks on an item I am trying to pull the valuemember associated with the record in the dataset and assign it a variable so I can use this as criteria in a search."
I have gotten all the same errors as you.[ponder]
Thanks
 
Well thank you for your thoughtfullness Sam225
We are still waiting...
 
this works for me with an ACCESS DB. the list box is populated with the key, when the user selects one it is assigned to the variable and used as selection criteria for Crystal Reports.

txtProjectNumber.Text = lstSelectProject.GetItemText(lstSelectProject.SelectedItem)
 
Hi,

I am assigning a drop-down list with displaymember and valuemember property. User can select multiple items from this drop-down list.

With lstCountry
.DataBindings.Add(New System.Windows.Forms.Binding("SelectedValue", DsPersonal, "Person.CountryId"))
.DataSource = DsPersonal.Country
.DisplayMember = "CountryName"
.ValueMember = "CountryId"
End With

Now I want to access all the valuemember item of all the selected. I want to do this using for..next OR for..each loop..

Can anybody he in doing this.. ?

How to access the respective valuemember for a particular index ?

Thnx a lot for the help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top