Want to return an object similar to DataRowView from ComboCloseUp event for MultiColumnComboBoxCellType

Posted by: j2associates on 8 September 2017, 1:26 pm EST

  • Posted 8 September 2017, 1:26 pm EST

    Hello all,


    We have a spread with several MultiColumnComboBoxCellTypes defined for various columns. I would like to write a general purpose function for the ComboCloseUp event that would take as an input parameter e.EditingControl. I would like the function to return the selected row of data so that I could fill in related column data, similarly to the way you can use the SelectedItem in a Windows Forms combo box which is a DataRowView pointing to a complete row of data from the underlying data source. This allows you do reference individual columns specifically with code like: CType(Me.ComboBox1.SelectedItem, DataRowView).Row("Column1"), etc in the SelectedIndexChanged event. Thanks in advance for any ideas and/or suggestions!

  • Replied 8 September 2017, 1:26 pm EST

    Thanks ScottS! So if you use True with GetDataView does that mean you are getting a separate, different object such that the following is True?


    ? Me.FpSpread1.ActiveSheet.GetDataView(False) Is Me.FpSpread1.ActiveSheet.GetDataView(True) = False

  • Replied 8 September 2017, 1:26 pm EST

    Hello,


    In the ComboCloseUp event, you can use code like the following.


    Private Sub FpSpread1_ComboCloseUp(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.EditorNotifyEventArgs) Handles FpSpread1.ComboCloseUp


    Dim ss As FarPoint.Win.Spread.FpSpread = CType(CType(FpSpread1.Sheets(0).GetCellType(1, 1), FarPoint.Win.Spread.CellType.MultiColumnComboBoxCellType).SubEditor, FarPoint.Win.Spread.FpSpread)


    Dim dr As DataRow = CType(ss.Sheets(0).GetDataView(True), DataView).ToTable().Rows(ss.ActiveSheet.ActiveRowIndex)


    End Sub

  • Replied 8 September 2017, 1:26 pm EST

    As always, thanks for the quick turn-around! Below is a function that I created to do the above. I have a couple questions regarding your code and the code below.


    1. I noticed you used True with the GetDataView method and I used False in my code below. What determines which value you should use?


    2. The long modelRow line below is something that I got off of the forums a long time ago. If I remember correctly, it was to help ensure that deleted, added, inserted and sorted rows did not result in an incorrect row being returned. Is the code valid in this context or does it needlessly complicate things?


        Private Function GetSelectedItem(ByVal subEditor As FpSpread) As DataRow
            Try
                With subEditor.ActiveSheet
                    Dim modelRow As Integer = DirectCast(.Models.Data, Model.DefaultSheetDataModel).GetDataRowFromModelRow(.GetModelRowFromViewRow(.ActiveCell.Row.Index))
                    Return .GetDataView(False).Item(modelRow)
                End With
            Catch ex As Exception
                Throw
            End Try
        End Function 'GetSelectedItem


     

  • Replied 8 September 2017, 1:26 pm EST

    Hello,


    1) The parameter passed into the GetDataView method will determine whether to get the DataView stored in the SheetView or recreate the DataView object.


    2) Since this is the sub editor being used for the MultiColumnComboboxCellType, there is not a need to worry about rows being inserted or deleted. If you implemented sorting, then you would need to use the GetModelRowFromViewRow method, but you would not need to turn around and call the GetDataRowFromModelRow.

  • Replied 8 September 2017, 1:26 pm EST

    Hello,


    This is not necessarily true. If no changes have been made to the DataTable (used to create the DataView) or to the Spread that has not be saved to the DataTable, then the objects should be the same (at least Reference.Equals).

  • Replied 8 September 2017, 1:26 pm EST

    If Reference.Equals is True, then what is the difference between the two parameter values?
  • Replied 8 September 2017, 1:26 pm EST

    Hello,


    Most of the times there is no difference in the DataView returned by this method. It is possible though for either the Spread's DataModel or the DataTable used to create the DataView has been changed and this could cause different results based on the paramater you pass in.

  • Replied 8 September 2017, 1:26 pm EST

    Thanks for the explanation.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels