如何将一些项输入到datagridview行 [英] how to input some items to a datagridview row

查看:94
本文介绍了如何将一些项输入到datagridview行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将一些项目合并到txtcari.text(搜索商品)按键的datagridview行,我使用的编码:

how to incorporate some items to a datagridview row of txtcari.text (search goods) key press, the coding that I use:

Private Sub txtcari_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtcari.KeyDown
    Select Case e.KeyCode
        Case Keys.Enter

            kon.Close()
            kon.Open()
            perintah.Connection = kon
            perintah.CommandType = CommandType.Text
            perintah.CommandText = "select * from barang where barangid='" & txtcari.Text & "'"
            cek = perintah.ExecuteReader
            cek.Read()
            If cek.HasRows Then
                Dim i As Integer
                i = dgjual.CurrentRow.Index
                Dim baris As DataGridViewRow = dgjual.CurrentRow
                baris.Cells(0).Value = txtcari.Text
                baris.Cells(1).Value = cek.Item("barangnama")
                baris.Cells(2).Value = cek.Item("barangharga")
                baris.Cells(3).Value = 1
                'baris.Cells(4).Value = ""

                Dim kode As String = baris.Cells(0).Value
                Dim nama As String = baris.Cells(1).Value
                Dim harga As Double = baris.Cells(2).Value
                Dim qty As Integer = baris.Cells(3).Value
                Dim tot As Double = baris.Cells(4).Value

                Dim barisbaru As Object() = New Object() {kode, nama, harga, qty, tot}
                dgjual.Rows.Add(barisbaru)

                txtcari.Text = ""

            Else
                MsgBox(ex.Massage)
            End If
            cek.Close()
            kon.Close()



但我的编码不太成功,因为每个项目我总是看2件ame项目一次,请帮助我掌握...谢谢你


but my coding is less successful, because each item I put 2 pieces always look the same item at a time, please help me master ... thank you

推荐答案

我的意思是..当密钥时,总是在单元格DataGrid中的相同2处执行相同的数据按..
i mean.. always perform the same data at the same 2 in cell DataGrid when key press ..


这篇关于如何将一些项输入到datagridview行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆