Results 1 to 4 of 4

Thread: DataGrid Help . . .[RESOLVED]

  1. #1

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Resolved DataGrid Help . . .[RESOLVED]

    Is it possible to use a selected row in a DataGrid to fill in textboxes from the fields? If so, how.

    Thanks,
    CP
    Last edited by milkmood; May 24th, 2005 at 05:45 PM.

  2. #2
    Addicted Member
    Join Date
    Jan 2005
    Posts
    136

    Re: DataGrid Help . . .

    im not too sure if this is what u want.give it a try
    VB Code:
    1. textBoxr1.text=datagrid.Item(datagrid.CurrentRowIndex, 0)
    0=first column in datagrid
    1=second
    .....

  3. #3

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Re: DataGrid Help . . .

    We're on the right track now...I get:

    An unhandled exception of type 'System.NullReferenceException' occurred in MyApplication.exe

    Additional information: Object reference not set to an instance of an object.

    And it hi-lites the first line in yellow. If I comment out the first line, it hi-lites the second line, and so on.

    'pm' is the main form of my solution (not the one in focus now), the form I'm working on has a datagrid with a select and a cancel button beneath it. The idea is to select a row in the datagrid, and move the data in that row to the textboxes on the main form. I suspect I'm handling the move to the main form wrong, but I'm not sure.

    VB Code:
    1. Private Sub btnCustSearchSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCustSearchSelect.Click
    2.  
    3.         Dim pm As PartsManager
    4.  
    5.                'Crashes on this line first
    6.             pm.txtCustomerName.Text = grdCustSearchResults.Item(grdCustSearchResults.CurrentRowIndex, 0)
    7.             pm.txtCustomerNumber.Text = grdCustSearchResults.Item(grdCustSearchResults.CurrentRowIndex, 1)
    8.             pm.txtCustomerAddress.Text = grdCustSearchResults.Item(grdCustSearchResults.CurrentRowIndex, 2)
    9.             pm.txtCustomerAddress2.Text = grdCustSearchResults.Item(grdCustSearchResults.CurrentRowIndex, 3)
    10.             pm.txtCustomerPOBox.Text = grdCustSearchResults.Item(grdCustSearchResults.CurrentRowIndex, 4)
    11.             pm.txtCustomerCity.Text = grdCustSearchResults.Item(grdCustSearchResults.CurrentRowIndex, 5)
    12.             pm.txtCustomerState.Text = grdCustSearchResults.Item(grdCustSearchResults.CurrentRowIndex, 6)
    13.             pm.txtCustomerZip.Text = grdCustSearchResults.Item(grdCustSearchResults.CurrentRowIndex, 7)
    14.             pm.txtCustomerContact.Text = grdCustSearchResults.Item(grdCustSearchResults.CurrentRowIndex, 8)
    15.             pm.txtCustomerPhone.Text = grdCustSearchResults.Item(grdCustSearchResults.CurrentRowIndex, 9)
    16.             pm.txtCustomerNotes.Text = grdCustSearchResults.Item(grdCustSearchResults.CurrentRowIndex, 10)
    17.             pm.txtCustomerLastUpdate.Text = grdCustSearchResults.Item(grdCustSearchResults.CurrentRowIndex, 11)
    18.             pm.txtCustomerUpdatedBy.Text = grdCustSearchResults.Item(grdCustSearchResults.CurrentRowIndex, 12)
    19.             pm.chkCustShipTo.Text = grdCustSearchResults.Item(grdCustSearchResults.CurrentRowIndex, 13)
    20.             pm.chkCustKeepInventory.Text = grdCustSearchResults.Item(grdCustSearchResults.CurrentRowIndex, 14)
    21.  
    22.         Me.Close()
    23.     End Sub

  4. #4

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Resolved Re: DataGrid Help . . .

    I got it. Geez, I'm solving all these problems myself. Maybe I should be the MVP.

    I ended up getting the data back to the parent form using code in the parent from instead of pushing it to the parent form from the child form with the datagrid.

    Simpler than beans, there's a button on the child form that says "Select" but all it really does is closes the child form because the data has already been returned to the parent form once a row is selected ; here's the whole routine:

    VB Code:
    1. Public Sub btnCustomerSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCustomerSearch.Click
    2.         Dim srch As String
    3.         Dim sqls As String
    4.         Dim dss As New DataSet
    5.         Dim das As New Odbc.OdbcDataAdapter
    6.         Dim csreturn As New PartsLifeCycleManager.frmCustSearch
    7.  
    8.         srch = txtCustomerSearch.Text
    9.         sqls = "SELECT * FROM customer WHERE LOWER(customername) LIKE %" & srch.ToLower & "% ORDER BY customername ASC;"
    10.         das = New Odbc.OdbcDataAdapter(sqls, con)
    11.         dss.Clear()
    12.         das.Fill(dss, "customer")
    13.  
    14.  
    15.         If dss.Tables("customer").Rows.Count < 1 Then
    16.             MessageBox.Show("No record found", "No Record", MessageBoxButtons.OK)
    17.             Exit Sub
    18.            
    19.         Else
    20.             csreturn.grdCustSearchResults.DataSource = dss.Tables("customer")
    21.             csreturn.ShowDialog()
    22.  
    23.             txtCustomerName.Text = csreturn.grdCustSearchResults.Item(csreturn.grdCustSearchResults.CurrentRowIndex, 0)
    24.             txtCustomerNumber.Text = csreturn.grdCustSearchResults.Item(csreturn.grdCustSearchResults.CurrentRowIndex, 1)
    25.             txtCustomerAddress.Text = csreturn.grdCustSearchResults.Item(csreturn.grdCustSearchResults.CurrentRowIndex, 2)
    26.             txtCustomerAddress2.Text = csreturn.grdCustSearchResults.Item(csreturn.grdCustSearchResults.CurrentRowIndex, 3)
    27.             txtCustomerPOBox.Text = csreturn.grdCustSearchResults.Item(csreturn.grdCustSearchResults.CurrentRowIndex, 4)
    28.             txtCustomerCity.Text = csreturn.grdCustSearchResults.Item(csreturn.grdCustSearchResults.CurrentRowIndex, 5)
    29.             txtCustomerState.Text = csreturn.grdCustSearchResults.Item(csreturn.grdCustSearchResults.CurrentRowIndex, 6)
    30.             txtCustomerZip.Text = csreturn.grdCustSearchResults.Item(csreturn.grdCustSearchResults.CurrentRowIndex, 7)
    31.             txtCustomerContact.Text = csreturn.grdCustSearchResults.Item(csreturn.grdCustSearchResults.CurrentRowIndex, 8)
    32.             txtCustomerPhone.Text = csreturn.grdCustSearchResults.Item(csreturn.grdCustSearchResults.CurrentRowIndex, 9)
    33.             txtCustomerNotes.Text = csreturn.grdCustSearchResults.Item(csreturn.grdCustSearchResults.CurrentRowIndex, 10)
    34.             txtCustomerLastUpdate.Text = csreturn.grdCustSearchResults.Item(csreturn.grdCustSearchResults.CurrentRowIndex, 11)
    35.             txtCustomerUpdatedBy.Text = csreturn.grdCustSearchResults.Item(csreturn.grdCustSearchResults.CurrentRowIndex, 12)
    36.             chkCustShipTo.Checked = csreturn.grdCustSearchResults.Item(csreturn.grdCustSearchResults.CurrentRowIndex, 13)
    37.             chkCustKeepInventory.Checked = csreturn.grdCustSearchResults.Item(csreturn.grdCustSearchResults.CurrentRowIndex, 14)
    38.  
    39.             csreturn.Dispose()
    40.             das.Dispose()
    41.             dss.Dispose()
    42.  
    43.          End If
    44.  
    45.     End Sub
    Last edited by milkmood; May 24th, 2005 at 05:28 PM.

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