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

Edited by pyTony: indent only your code, not explanations

6 Years
Discussion Span
Last Post by 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

replace this

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

with this

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


Edited by pyTony: Removed the model code template


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

Edited by pyTony: Pay attention to code tags!


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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.