none
Update Datagridview using textbox in VB.net RRS feed

  • Question

  • Dear All,

    I want to update all records in one column in Datagridview to the same value in textbox.

    Example:

    Textbox value: xxx

    But in datagridview:

    Column1:

    xx01

    xx02

    xx03

    so, i want to change it to be like this if i click on Button:

    Column1

    xxx

    xxx

    xxx

    How to write code in VB.net?

    Regards,

    Ratana, Cambodia

    Tuesday, February 19, 2013 1:08 AM

Answers

  • Hi Ratana,

    You can iterate through all DataGridView.Rows and assign the column value.

            For Each row As DataGridViewRow In DataGridView1.Rows
                row.Cells.Item("ColumName").Value = TextBox1.Text
            Next

    Best Regards,


    Bob Wu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, February 19, 2013 6:29 AM
    Moderator

All replies

  • Hi Ratana,

    You can iterate through all DataGridView.Rows and assign the column value.

            For Each row As DataGridViewRow In DataGridView1.Rows
                row.Cells.Item("ColumName").Value = TextBox1.Text
            Next

    Best Regards,


    Bob Wu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, February 19, 2013 6:29 AM
    Moderator
  • Thank Bob Wu-MT....my problem is sloved.

    Tuesday, February 19, 2013 7:52 AM
  • dear all,

    Update Datagridview using textbox in VB.net

      For Each row As DataGridViewRow In DataGridView1.Rows
                row.Cells.Item("ColumName").Value = TextBox1.Text
            Next

    this is my code:

        Private Sub update_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

            For Each row As DataGridViewRow In DataGridView1.Rows
                row.Cells.Item("ArtifactCodeDataGridViewTextBoxColumn").Value = TextBox1.Text
                row.Cells.Item("NamaDataGridViewTextBoxColumn").Value = TextBox2.Text
                row.Cells.Item("NopendaftaranDataGridViewTextBoxColumn").Value = txtno.Text
                row.Cells.Item("ButiranDataGridViewTextBoxColumn").Value = txtbutiran.Text
                row.Cells.Item("DimensiLDataGridViewTextBoxColumn").Value = txtL.Text
                row.Cells.Item("DimensiPDataGridViewTextBoxColumn").Value = txtP.Text
                row.Cells.Item("KeadaanDataGridViewTextBoxColumn").Value = txtkeadaan.Text
                row.Cells.Item("DiperolehidaripadaDataGridViewTextBoxColumn").Value = txtdiperolehi.Text
                row.Cells.Item("TarikhdiperolehiDataGridViewTextBoxColumn").Value = dtpdate.Text
                row.Cells.Item("NofailberdaftarDataGridViewTextBoxColumn").Value = txtnofail.Text
                row.Cells.Item("TempatsimpanDataGridViewTextBoxColumn").Value = cbotempat.Text
                row.Cells.Item("RujukanDataGridViewTextBoxColumn").Value = txtrujukan.Text
                row.Cells.Item("TempatasalDataGridViewTextBoxColumn").Value = txtasal.Text

       Next

        End Sub

    don't have error but when i update one data from textbox then when i view in datagridview
    the data which is I update before this , that change to all row no 1 data that  i want to update

    hope can help me...urgentt,,please..


    Tuesday, May 28, 2013 5:47 AM