hi... anybody want to help me to solved my problem
i want to get value from gridview column into textbox. i have DGS4 as my gridview . and i want to use query like i used bellow. i uses some code from @luc001 but it stil not working.

this is my code :

    da2 = New MySqlDataAdapter("select * from pegawai where kode_pegawai='" & TextBoxDataKode.Text & "' ", "server=localhost;User Id=root;database=databasecuti")

    ds2 = New DataSet

    da2.Fill(ds2, "pegawai")
    DGS4.DataSource = ds2.Tables("pegawai")


    Dim GridView As New DataView(ds2.Tables("pegawai"))
    DGS4.DataSource = GridView

    TextBoxDataKode.Text = DGS4.Item(1, GridView.SelectedRows(0).Index).Value

Enter the correct cell no and then on the click of the row in datagrid view u will get the cell value in the text box

textbox1.Text = DGS4.CurrentRow.Cells(0).Value

replace this

TextBoxDataKode.Text = DGS4.Item(1, GridView.SelectedRows(0).Index).Value

with this

TextBoxDataKode.Text = DGS4.Item(1, DGS4.currentrow.Index).Value.tostring()

Regards

Try this

textboxdatakode.text = dgs4(i,j)

where i as columnindex and j as rowindex

Just make sure that the cell value u are entering in the code is correct...u can write the code in the datagridview cellclick event ...
as and when u click on the datagridview cell the value will be displayed in ur textbox

QUOTED FROM poojavb:

Enter the correct cell no and then on the click of the row in datagrid view u will get the cell value in the text >box

textbox1.Text = DGS4.CurrentRow.Cells(0).Value

Do not forget to use ToString() method on the end, else will be a compile time error:

textbox1.Text = DGS4.CurrentRow.Cells(0).Value.tostring()

Mitja - Actually I tried without using ToSTring() funtion but I did not get the compiletime error....

It worked properly for me....so pasted without ToSTring() :)

dim obj as new datagridviewselectedcellcollection = datagridview1.selectedcellcollection
textbox1.text=obj.item(0).cell(0).value

use this TextBoxDataKode.Text = DGS4.CurrentRow.Cell(0).Value.ToString() instead of TextBoxDataKode.Text = DGS4.Item(1, GridView.SelectedRows(0).Index).Value

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.