Populate a txtbox field, clicking on a datagridview cell from a datatable

  • 14 years ago

    Hello. 1st Message.  If too long, pls forgive. Question is regarding  DataTables. Wet behind the ears with some earlier experience w-VB6 & SQl. No, no expert. I analyse data for use by the big guys and while doing so learning how they use it as far as datagrids, datatables, web & forms. Anyway. Simply put. I have a form with 3 datagridviews (Objects)bringing in 3 tables to have data compared and hopefully edited. Not using DataSets but DataTables instead. Struggle is: How do I code an event for clicking on the datagridview field & populate a text box object with the datagrid data selected (Clicked). Hope this is the right forum for this simple but long query.  Here is some of the code:

    'My Connection String....
    MyConn.ConnectionString = My.Settings.MyConn

    DT = New DataTable
    DT2 = New DataTable
    DT3 = New DataTable

    'Setting my SelectCommand properties....
    MyCmd.CommandType = CommandType.Text
    MyCmd.CommandText = "SELECT Top 10 ODppid,ODid,PayPlanStatus FROM ODPayPlan ORDER BY ODppid"

    MyCmd2.CommandType = CommandType.Text
    MyCmd2.CommandText = "SELECT Top 10 ODid, TransCode,TRid,TransVar FROM ODTrans ORDER BY ODid"

    MyCmd3.CommandType = CommandType.Text
    MyCmd3.CommandText = "SELECT Top 10 ODid,PropId,vVarChar,vDate FROM ODdata ORDER BY ODid"

    Dim MyQryString As String = MyCmd.CommandText
    Dim MyQryString2 As String = MyCmd2.CommandText
    Dim MyQryString3 As String = MyCmd3.CommandText

    Dim MySDA As SqlDataAdapter = New SqlDataAdapter(MyQryString, MyConn)
    Dim MySDA2 As SqlDataAdapter = New SqlDataAdapter(MyQryString2, MyConn)
    Dim MySDA3 As SqlDataAdapter = New SqlDataAdapter(MyQryString3, MyConn)

    'Fill the DataGrid...
    Thank You, DeaconKen

  • 14 years ago
    Key is event onSelectedCellChanged or somehow like that called crap, which gives you cell index, and key #2 is dg property CurrentRowIndex, which provides pointer to row.
    If more data  selected, vb2003 has problems to get pointers. In more rcnt versions good changes, but in this 'old' 2003 you must go from 0 to Error and check .isSelected... :)

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves” - Alan Kay