Using VB.Net
Windows application
Form (Gridview and Textbox)
GridView1
ID Name
001 Rajan
002 Sajan
103 Prathev
104 vijayan
....
Conditon
When i clicked the up and down arrow (keyboard) in the Gridview1 (id or name row), then selected cell should display in the textbox and also when i enter some numbers means, that entered number should appear in the textbox and also entered related ID or name should display in the gridview1
For Example
If i press 0, that 0 should display in the textbox, and gridview display like
ID Name
001 Rajan
002 Sajan
If i press 1, that 1 should display in the textbox, and gridview display like
ID Name
103 Prathev
104 vijayan
Tried Code for displyaing in the girdview
Dim conObjects As New ConnectionObjects
conObjects.OpenConnection()
Dim cmd As SqlCommand
Dim ds As DataSet
Dim ada As SqlDataAdapter
cmd = New SqlCommand("Select ID, Name from employee where id like '%" & textbox1.Text & "%' ", conObjects.myConnection)
ada = New SqlDataAdapter(cmd)
ds = New DataSet
开发者_开发知识库 ada.Fill(ds, "employee")
gridview1.DataSource = ds.Tables(0)
Expected answer
-> In which gridview event i have to write a code
-> If i press up or down arrow, then selected cell should display in the textbox
-> If i enter some number or characters, that numbers or character should display in the textbox and selected related values should display in the gridview
How to do this.
Need help or vb.net code.
You can bind your dataSource
to dataGridview
and TextBoxes
.
Here is sample code (Add dataGridView1, TextBox1,TextBox2):
Private Sub YourForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
dt.Columns.Add("No")
dt.Columns.Add("Name")
dt.Rows.Add(1, "A")
dt.Rows.Add(2, "B")
DataGridView1.DataSource = dt
TextBox1.DataBindings.Add("Text", dt, "No")
TextBox2.DataBindings.Add("Text", dt, "Name")
End Sub
精彩评论