Set the selectedindex of a datagrid

F

Fernando Lopes

Hi there.
I have a customer's address grid in my web application.
After I searched for a customer I showded all his addresses.
One of these addresses is the ship address.
In the search, I gotten the addressId of this ship address.
The datakey of datagrid is the AddressID.
I want to keep selected the grid row of this address.

How can I do that?

tks.

Fernando
 
F

Fernando Lopes

Ok Kostadin.
But, I have the AddressID, not the index of the datagrid.

index addressid street
1 1001 aaaaaaaaa
2 736 bbbbbbbbbb

Understand?

tks.

Fernando
 
G

Guest

Have you tried this?

index = DataGrid1.SelectedIndex
key = DataGrid1.DataKeys(index)

Sandy
 
F

Fernando Lopes

Tks Sandy, the proble is
I don't have de index. I wrote just to watch the differences betweeen the
index and de addressID.

So, I just have the addressID (int) and the grid like:
addressid street
1001 aaaaaaaaa
736 bbbbbbbbbb

Tks again

Fernando
 
B

Brock Allen

If the AddressID is in the DataGridKeys collection (meaning it was in there
because you set "AddressID" as the DataKeyField) then you can find it in
there. So find the index by searching the DataKeys collection.
 
F

Fernando Lopes

Ok Brock!
Tks a lot!
Now works!


Brock Allen said:
If the AddressID is in the DataGridKeys collection (meaning it was in there
because you set "AddressID" as the DataKeyField) then you can find it in
there. So find the index by searching the DataKeys collection.
 
G

Guest

Fernando -

Try this:

Dim AddressIDIndex as Integer
Dim AddressIDKey as Integer
AddressIDIndex = NameOfYourDataGrid.SelectedIndex
AddressIDKey = NameOfYourDataGrid.DataKeys(AddressIDIndex)

Sandy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top