none
Filling a datarow with row selected from DataGridView

    Question

  • I am working on a project that allows the user to search the database for particular records, then passes the record that the user chooses to the main form to be manipulated or changed. Yes I am aware that I could let the user change the values in the datagridview, but I do not wish to do that this way. This is the code for the event that fires when the user presses the button to return the selected row:

    Private Sub returnBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles returnBtn.Click
    
        Dim ActRow As ds.ActivityRow
        Dim rowNum As Integer
        rowNum = Convert.ToInt32(searchDataGrid.SelectedCells.Item(0).Value)
        ActRow = Ds.Activity.FindByActID(rowNum)
        LoadFoundValues(ActRow)
        ActivityLogForm.Focus()
    
      End Sub
    

    ds is my dataset, searchDataGrid is the datagridview

    The explicit problem that I am having is that ActRow is not being filled with the ds.Activity.FindByActId(rowNum) function

    Any help with this would be greatly appreciated, and I hope that this was posted in the proper place

    Thursday, May 05, 2011 4:49 AM

All replies

  • Wy don't you not simply use the currency manager (has nothing to do with money) to get the datarow.

    This is 1990 style of code.

    See this simple sample on our website

    http://www.vb-tips.com/CurrencyManager.aspx


    Success
    Cor
    Thursday, May 05, 2011 5:19 AM
  • Thank you very much! This did work, but is there anyway for the currency manager to return a strongly typed data row i.e. I want it to return an ActivityRow in lieu of a generic datarow. Here is the code I used:
    Private Sub returnBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles returnBtn.Click
    
        Dim dr As DataRow
        Dim cm As CurrencyManager = CType(Me.BindingContext(searchDataGrid.DataSource, searchDataGrid.DataMember), CurrencyManager)
        Dim dv As DataView = CType(cm.List, DataView)
        dr = dv.Item(cm.Position).Row
        LoadFoundValues(dr)
        ActivityLogForm.Focus()
    
      End Sub
    

    Thursday, May 05, 2011 5:55 AM