Results 1 to 11 of 11

Thread: Datagrid values to textbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    4

    Datagrid values to textbox

    Hi all,

    I am very new to VB. I am using VS2005 vb. I have two textboxes and one grid with two columns

    I want to populate the grid values to text box while clicking the exact row?

    Is it possible?


    can any one give me the solution..?

    Thanks
    Krishna
    Last edited by csk_abk; Oct 24th, 2007 at 10:36 AM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Datagrid view to textbox

    Moved to VB.NET

  3. #3
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Datagrid values to textbox

    TextBox1.Test = DatagridView1.Item(0,e.RowSelected()).ToString()
    TextBox2.Test = DatagridView1.Item(1,e.RowSelected()).ToString()
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    4

    Re: Datagrid values to textbox

    Mazz1 Thanks for your reply. But I am getting error like
    "'RowSelected' is not a member of 'System.Windows.Forms.DataGridView"

    Thanks
    Krishna

  5. #5
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Datagrid values to textbox

    Sorry should be

    e.RowIndex()

    On the datagrid click or double click event
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Datagrid values to textbox

    Please do not bump your thread.

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    4

    Re: Datagrid values to textbox

    Sorry friend No Luck. Its not working!!

    In my text box i am getting like "DataGridViewTextBoxCell { ColumnIndex=0, RowIndex=1 }"

    -- krishna

  8. #8
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Datagrid values to textbox

    This works for me every time:

    vb.net Code:
    1. Private Sub dgDances_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgDances.CellDoubleClick
    2.         If e.RowIndex() < 0 Then
    3.             Exit Sub
    4.         End If
    5.         Me.intDancePK = Integer.Parse(Me.dgDances.Item(0, e.RowIndex()).Value.ToString())
    6.         Me.txtDanceName.Text = Me.dgDances.Item(1, e.RowIndex()).Value.ToString()
    7.         Me.cmdDelete.Enabled = True
    8.     End Sub
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  9. #9
    Member PokeyDillard's Avatar
    Join Date
    Jul 2005
    Location
    beating my head against my desk in Indianapolis, IN
    Posts
    58

    Re: Datagrid values to textbox

    Change .ToString to .Value

    Code:
    TextBox1.Test = DatagridView1.Item(0, e.RowIndex).Value
    TextBox2.Test = DatagridView1.Item(1, e.RowIndex).Value
    "The greatest mistake you can make in life is to be continually fearing you will make one."
    -Elbert Hubbard

    Custom Colors on Disabled Controls

  10. #10

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    4

    Re: Datagrid values to textbox

    Now its working. I think we have missed the "Value" Word in previous sysntax.

    Thnaks Mazz

    Krishna

  11. #11
    Addicted Member riechan's Avatar
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    254

    Re: Datagrid values to textbox

    Is this thread still available for posting? I would just like to ask why is it that the datagrid only "reacts" when I click on the second column...
    ====================
    ほんとにどもありがとう!

    Rie Ishida

Posting Permissions

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



Click Here to Expand Forum to Full Width