选定的内容未显示在文本框中

时间:2011-10-08 11:08:40

标签: vb.net

使用VB.Net

Windows应用程序

表格(网格视图和文本框)

GridView1

ID Name

001 Rajan
002 Sajan
103 Prathev
104 vijayan
....

Conditon

当我单击Gridview1(id或名称行)中的向上和向下箭头(键盘)时,所选单元格应显示在文本框中,当我输入一些数字时,输入的数字应出现在文本框中, 还输入相关的ID或名称应显示在gridview1

例如

如果按0,则0应显示在文本框中,gridview显示为

ID Name

001 Rajan
002 Sajan

如果按1,则1应显示在文本框中,gridview显示为

ID Name

103 Prathev
104 vijayan

尝试在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)

预期答案

-> 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

如何做到这一点。

需要帮助或vb.net代码。

1 个答案:

答案 0 :(得分:1)

您可以将dataSource绑定到dataGridviewTextBoxes

以下是示例代码(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