String Error

  • Thread starter Thread starter Ivan Weiss
  • Start date Start date
I

Ivan Weiss

I am assigning a string variable with my sql statement getting the item
from a listview filled from a database.

I am getting an error saying that & is not defined for types 'String'
and Systems.Windows.Forms.ListViewItems.

I am using an index of 0 because the value I want is in the first column
(it is the customer ID from the database)

Dim mySqlString As String

'Define sqlString that deletes from database
mySqlString = "DELETE from Customers WHERE Cust_ID = '" &
ListView.SelectedItems(0) & "'"

-Ivan
 
You are trying to take the selected item and treat it as a string. Does
"SelectedItems(0)" have a .value property or something similar that exposes
the text of the selected item?

Essentially, you are treating a type like a value.
 
Ivan The Terrible ?

You need to you the 'ListViewItem.Text' property to get the items text.

Regards - OHM
 
I feel like Ivan the terrible with all of the errors I have been finding
throughout writing this app but they are slowly getting resolved.

I changed it to listview.text and that got rid of the error. However,
how does it know what column to grab text from? I only need to confirm
my id = the value in the first column of my listview.

Thank for your help, it is truly appreciated!

-Ivan
 
Hi Ivan,

I think you go in the wrong direction.

The listview is a multiselect control.
So you first have to determ what rows are selected.

For that is the property selecteditems
I am typing this rough so watch for typos or stupiditys
\\\
dim lsv as listviewItem
for each lsv in mylistview.selectedItems
doDelete(lsv.text)
' or better doDelete(lsv) because than you have the whole row.
' the other columns are lsv.subitems(x).text
next
///

I hope this helps a little bit

Cor
 
This is one of the examples of someone posting and not coming back or
answering.

Regards - OHM
 
I dont understand. What do you mean this is an example of someone
posting and not coming back and answering. I have posted three
responses/follow-ups after the first inquiry?

-Ivan
 
I disabled multi-select in my listview. I only want the user to be able
to select one row at a time.

The rows are customers from my database so I am more concerned with
deleting from the database than the listview.

Once I am done with the delete than I am calling my database class which
has a method to refresh the listview from the database. How do I get
the value from one column in the listview not the entire row?

-Ivan
 
In the thread I am looking at now. I see three posts only. Your original
post, the one above this reply and one other.

Regards - OHM
 
I'll let you continue with this post Cor, I really dont have the energy to
do anymore today.

Regards - OHM
 
Ivan,

Did you tried the code I did message you?

I thought that I did describe it there, what was it that not was working?

Cor
 
Ivan

Now I see it I think, you did not understand that piece of

doDelete(lsv.text)

That is ment as a function to suply the lsv.text to your delete instructions
for your database.

This code below(the same as I suplied before) is of course normal placed in
an event from the listview or if you wish in a special button event.

With that the row will not be deleted from the listview, that you have to do
yourself.

And if it is a multiselect of a single select is not important, it works in
both cases.

I hope it is more clear for you now, otherwise ask again?

Cor


\\\
dim lsv as listviewItem
for each lsv in mylistview.selectedItems
doDelete(lsv.text)
' or better doDelete(lsv) because than you have the whole row.
' the other columns are lsv.subitems(x).text
next
///
 
Back
Top