Automatic values comes to DataGridView from Textbox
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Automatic values comes to DataGridView from Textbox

  1. #1
    Join Date
    Aug 2007
    Posts
    38

    Automatic values comes to DataGridView from Textbox

    Hello All Experts,

    I have one textbox, if suppose if i type anything in that textbox then its should automatically comes to DataGridView particular cell.

    Can any one have the code for doing this stuff?

    Regards,
    AKM

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,091

    Re: Automatic values comes to DataGridView from Textbox

    Hello.

    You just need to know the Row and Column number of the particular cell you'd like the text to be enetered.

    If I were to do this :

    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            DataGridView1.Rows(0).Cells(0).Value = TextBox1.Text 'Enter in 1st Row 1st Col
            DataGridView1.Rows(0).Cells(1).Value = TextBox2.Text 'Enter in 1st Row 2nd Col
            DataGridView1.Rows(0).Cells(2).Value = TextBox3.Text 'Enter in 1st Row 3rd Col
    
        End Sub
    It will enter TextBox1's text in the first column of the first row; TextBox2's text into the second column of the first row, and TextBox3's text into the third column of the first row.

    EDIT: You mentioned "automatically". Do you want this text to appear as you are busy typing into the TextBox? I'd then suggest the Change event, but, the proper advice would be to use either the LostFocus or Leave events. The reason why I say so is that you have to think about validating the entered contents.

    I hope it helps!

    Hannes
    Last edited by HanneSThEGreaT; July 6th, 2010 at 08:00 AM.

  3. #3
    Join Date
    Aug 2007
    Posts
    38

    Re: Automatic values comes to DataGridView from Textbox

    Please note that this logic only apply to first row, not the particular row which i have selected by below coding logic.

    Code:
     Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
    
                DocEntry.Text = DataGridView1.Rows(e.RowIndex).Cells("DocEntry").Value
                CardNameEdit.Text = DataGridView1.Rows(e.RowIndex).Cells("CardName").Value
                CardSerialEdit.Text = DataGridView1.Rows(e.RowIndex).Cells("CardSerialNo").Value
                CustName.Text = DataGridView1.Rows(e.RowIndex).Cells("CustomerName").Value
                Branch.Text = DataGridView1.Rows(e.RowIndex).Cells("BranchName").Value
                CardStatus.Text = DataGridView1.Rows(e.RowIndex).Cells("CardStatus").Value
    End Sub
    Above logic is like that if i select any row in DataGridview its displaying its value in Texboxes.
    Now what i want if i change that anytextbox value then its automatically comes to datagridview
    and the Datagridrow status should be in update mode.

    Regards,
    AKM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center