DoublePress ListBox to open and edit data

Hiya, going round the houses here, just need a couple of pointers please.

so, ListBox populated with data. User DoublePresses a row which then opens the EditCustomer window (EditCustomer.Show)

Then i’m thinking i can run a sql query to populate my text fields on the Edit customer window using a method.

What i dont know is how to capture the custID and pass it to the EditCustomer method so that I can run the query.

Hope that kind of makes sense

thank you
zac

Where is the custID? If it’s in (say) the RowTag for the row, then get it from there. Then pass this as an argument to a small method which stores it into a property of your EditCustomer window, then does the EditCustomer.show. That window then has the custID in that property.

I display the custID in the listbox although I actually call the listbox column header ‘Customer ID’

Ok let me play about with what you’ve said. thank you Tim

The small method I referred to should be a mthod of EditCustomer. Then you call it from DoublePressed with:

EditCustomer.mymethod (custID)

Then in the method you have:

me.localCustID = custID
me.Show ()

You will find many information there:
https://documentation.xojo.com/topics/databases/supported_engines/sqlite/sqlite_basics.html#sqlite-basics

in the first example, adapt the line to:


app.db.SelectSQL("select * from person where id'='" + UniqueID + "'")

where UniqueID comes from the double cliked Row. that is the Unique ID of the Record you want.

ok, don’t laugh :sweat_smile:

would something like this work in the double pressed

' Get the selected customer ID
Dim custID As Integer = CustActiveListBox.SelectedRow.custID

' Open the EditCustomer window
EditCustomer.Show

' Pass the customer ID to the EditCustomer window
EditCustomer.Parameters.Add("custID", custID)

sorry… i see there has been two more replies whilst i was typing that out. let me see…

All of us have started at some time.

I add my IDs as RowTags:

me.RowTagAt(me.LastAddedRowIndex) = CustID

Then give your window constructor as parameter CustomerID and use the RowTag in the constructor.

ok so here goes… takes me ages to type this stuff:

in my ListBox DoublePressed I have:

//Get the selected customer ID
me.RowTagAt(me.LastAddedRowIndex) = "Customer ID"

//Open the EditCustomer window
EditCustomer.Show

Then in my EditCustomer window Method I have:


//set this stuff
EditCompName.Text = ""
EditContactname.Text = ""
EditTel.Text = ""
EditMob.Text = ""
EditEmail.Text = ""


//load it into the fields (help, the 1st and second line are throwing an error)
Dim customerData As Customer
customerData = Customer.GetCustomerByID(Me.Parameters("custID").Value)
EditCompName.Text = customerData.custCompany
EditContactname.Text = customerData.custName
EditTel.Text = customerData.custTel
EditMob.Text = customerData.custMob
EditEmail.Text = customerData.custEmail

error

The problem is i read so much stuff online and on this forum I think I end up mixing bits of code and anything i do rarely works 1t time without intervention/help from someone else!

From where this comes ?

That is why Xojo complains. You may have fogotten something… (to declare it)…

Go to the documentation to know how to open a data base file…

You haven’t defined your Customer class.

I think coding is not for me. I’ve been round in circles for days now. I was hoping to come back to this tread and post a working example. I’m going to give up for now. Maybe i’ll return in the future when i have more time to dedicate to it.
thank you for the help
zac

It’s no good going round in circles. You posted some error messages upthread, and then I said that you hadn’t defined your “Customer” class. That is, no wonder there were error messages. And yet you didn’t get back to us here asking what I was talking about, or anything at all. You’re not going to make progress unless, if there’s something someone has said that isn’t clear, you don’t then get back to us and ask more questions.

1 Like

Thanks Tim, i do appreciate your reply. Take the Customer class as an example… I receive your help via the forum then i go off googling, rather than just firing back a question to you straight away saying “what class? how do I do that?”
I’m aware people on the forum don’t just want to write the code for me. So off i go to google where I find lots of information. Some of that info seems worth trying out. But by the time i’ve tried several different things ive got my code in a complete mess and decide to wipe it clean and start again.
I think you can imagine how easily I’m getting in a mess.
Sometime i come across a code snippet that looks like it might work, only to discover it’s old XoJo code and has been replaced! :face_with_peeking_eye:

Ive decided to revisit this again on the weekend. i’ve made a small amount of progress. Is ok to post for help on this same thread or should i start a new one please?
thank you
zac

1 Like