Link to home
Create AccountLog in
Avatar of Victor  Charles
Victor CharlesFlag for United States of America

asked on

Help with retreiving value of row when edon it.

Hi,

My grid contains 5 rows. How do I pass the value of the data in the row when I click on it?
The Grid is from componentone.

For example if my Grid contains


A
B
C
D

When I click on the first row, I would like to set s = A, when I click on the second row set s = B etc..

Thanks,

Victor
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

s = c1TrueDBGrid1.Columns[c1TrueDBGrid1.Col].CellText(c1TrueDBGrid1.SelectedRows[0])

Open in new window

Avatar of Victor  Charles

ASKER

Hi,

I tried the code below, changed [] to () because it was given me an error, but value for s = 0
for each row I select.

s = c1TrueDBGrid1.Columns(c1TrueDBGrid1.Col).CellText(c1TrueDBGrid1.SelectedRows(0))

Thanks,

Victor
u need to use this code in the click event handler of the grid.
can u try that?
Hi,

I receive the text of the first row (i.e.  s = A ) regardless which row I select.

Dim s as string
s = c1TrueDBGrid1.Columns(c1TrueDBGrid1.Col).CellText(c1TrueDBGrid1.SelectedRows(0))

Thanks,

Victor
Just read your post, will try it and get back to you.
I tried the code in the click event but still getting the value of the first row, regardless which row I click on.
I tried rowIndex but it still does not work.

s = c1TrueDBGrid1.Columns(c1TrueDBGrid1.Col).CellText(c1TrueDBGrid1.SelectedRows(rowIndex))
is it the 1st column?
Yes, I can't find the current row clicked on. also tried currentIndex but it did not work.

s = c1TrueDBGrid1.Columns(c1TrueDBGrid1.Col).CellText(c1TrueDBGrid1.SelectedRows(CurrentIndex))
i've added this to the grid handler and got it working every click:

private void c1TrueDBGrid1_Click(object sender, EventArgs e)
        {
            MessageBox.Show(c1TrueDBGrid1.Columns[c1TrueDBGrid1.Col].CellText(c1TrueDBGrid1.SelectedRows[0]));
        }

Open in new window

Can you please send me the VB.NET version.

Thanks.
	MessageBox.Show(c1TrueDBGrid1.Columns(c1TrueDBGrid1.Col).CellText(c1TrueDBGrid1.SelectedRows(0)))

Open in new window

I tried the code below which should be the same with your code but it still does not changethe value of s when I click on dirrent rows.


 Private Sub C1NSN_Click(sender As Object, e As System.EventArgs) Handles C1NSN_.Click
        Dim s As String
        s = C1NSN_.Columns(C1NSN_.Col).CellText(C1NSN_.SelectedRows(0))
        MsgBox(s)
    End Sub
Hi, correction.

Private Sub C1NSN_Click(sender As Object, e As System.EventArgs) Handles C1NSN.Click
        Dim s As String
        s = C1NSN.Columns(C1NSN_.Col).CellText(C1NSN.SelectedRows(0))
        MsgBox(s)
    End Sub
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
It works.

Thank You.

Victor
Hi again,

Not  sure what I did wrong, but when click on the grid the code in the click event does not execute, any ideas why the code does not execute?
u posted that it works, did u change anything?
I tried using the code in the selchange event since I need to use e.cancel = true, declared s as public, trying to undo my changes, but click event still does not trigger.
try add the event handler from the properties pane in visual studio, the AddHandler might be missing