Sahar Kiyan
Sahar Kiyan

Reputation: 67

how to add new row after filling all textboxes, not replace old row in gridview?

i wrote program in vb.net. in my page, i have 3 textbox. in Txt_CardBarcode_TextChanged ,i wrote this codes:

 Try
    Dim stream_CardBarcode As System.IO.MemoryStream = New System.IO.MemoryStream
    Dim cls As New Cls_Barcode
    Dim pic_CardBarcode As System.Drawing.Image = Nothing
    cls.btnEncode(pic_CardBarcode, Txt_CardBarcode.Text.Trim)
    pic_CardBarcode.Save(stream_CardBarcode, System.Drawing.Imaging.ImageFormat.Png)
    Dim f_cardBarcode As IO.FileStream = _
        New IO.FileStream("C:\fafa.png", IO.FileMode.Create, IO.FileAccess.ReadWrite)
    Dim b_cardBarcode As Byte() = stream_CardBarcode.ToArray
    f_cardBarcode.Write(b_cardBarcode, 0, b_cardBarcode.Length)
    f_cardBarcode.Close()
    Dim ds As DS_Test
    ds = New DS_Test
    Dim Val_LabelBarcode() = {stream_CardBarcode.ToArray, Txt_ICCID.Text.Trim}
    ds.Tables(2).Rows.Add(Val_LabelBarcode)
    crp_CardBarcode.SetDataSource(ds.Tables(2))
    Dim frm_CrpCardBarcode As New Frm_RepCardBarcode
    frm_CrpCardBarcode.CrystalReportViewer1.ReportSource = crp_CardBarcode
    GVSimInfo.DataSource = ds.Tables(2)
                ds.Tables(2).Rows.Add(1)
                GVSimInfo.Rows(GVSimInfo.Rows.Count - 1).Cells(0).Value = True
                ds.Tables(2).Rows(0).Item(0) = True
                ds.Tables(2).Rows(0).Item(1) = ""
                ds.Tables(2).Rows(0).Item(2) = Txt_ICCID.Text
                ds.Tables(2).Rows(0).Item(3) = ""
                ds.Tables(2).Rows(0).Item(4) = ""

now, in run time, after filling 3textbox, new row add to gridview , but when user want to more than filling textboxes, new row in grid view replace on old row!!! how to set new row add to grid view , instead of replace old row?

in my dataset, i put 3tables. tables(2) has 2 columns that save image barcode with byte array data type, but in my gridview ,i have 5 columns. in run time give me error dialog,it is images from it: enter image description here

Upvotes: 0

Views: 767

Answers (1)

Arpit
Arpit

Reputation: 12797

If your DGV is not bound to any data Source:

            GVSimInfo.Rows.Add(1);

If your DGV is bound to some Data Source then :

           ds.Tables(2).Rows.Add(1)

Add this code after your last text box is filled and new row is needed.

to set the values you can use :

ds.Tables(2).Rows(0).Item("Column_number") = "your text"


 Try
    Dim stream_CardBarcode As System.IO.MemoryStream = New System.IO.MemoryStream
    Dim cls As New Cls_Barcode
    Dim pic_CardBarcode As System.Drawing.Image = Nothing
    cls.btnEncode(pic_CardBarcode, Txt_CardBarcode.Text.Trim)
    pic_CardBarcode.Save(stream_CardBarcode, System.Drawing.Imaging.ImageFormat.Png)
    Dim f_cardBarcode As IO.FileStream = _
        New IO.FileStream("C:\fafa.png", IO.FileMode.Create, IO.FileAccess.ReadWrite)
    Dim b_cardBarcode As Byte() = stream_CardBarcode.ToArray
    f_cardBarcode.Write(b_cardBarcode, 0, b_cardBarcode.Length)
    f_cardBarcode.Close()
    Dim ds As DS_Test
    ds = New DS_Test
    Dim Val_LabelBarcode() = {stream_CardBarcode.ToArray, Txt_ICCID.Text.Trim}
    ds.Tables(2).Rows.Add(Val_LabelBarcode)
    crp_CardBarcode.SetDataSource(ds.Tables(2))
    Dim frm_CrpCardBarcode As New Frm_RepCardBarcode
    frm_CrpCardBarcode.CrystalReportViewer1.ReportSource = crp_CardBarcode
                ds.Tables(2).Rows.Add(1)
                GVSimInfo.Rows(GVSimInfo.Rows.Count - 1).Cells(0).Value = True
                ds.Tables(2).Rows(0).Item(0) = True
                ds.Tables(2).Rows(0).Item(1) = ""
                ds.Tables(2).Rows(0).Item(2) = Txt_ICCID.Text
                ds.Tables(2).Rows(0).Item(3) = ""
                ds.Tables(2).Rows(0).Item(4) = ""
                GVSimInfo.DataSource = ds.Tables(2)  <-------

Upvotes: 2

Related Questions