C1FlexGrid with DataMap that changes based on value in previous column

Posted by: softcomlimited on 1 August 2019, 6:05 pm EST

    • Post Options:
    • Link

    Posted 1 August 2019, 6:05 pm EST

    Hello,

    I am trying to use C1FlexGrid with a MultiColumnDictionary DataMap that changes based on value in previous column.

    When I change the value cols(“AcType”) the datamap for the next column cols(“SubAc”) changes to the corresponding set of values. However when I move to another row that has a different value in cols(“AcType”) and thus a different datamap for cols(“SubAc”) and I click the dropdown, the SubAc values in the other rows go blank, I guess because the key value is not in the list anymore.

    Can C1FlexGrid and datamap be used like this?

    Is there another way (different controls) to get this kind of thing to work?

    Thank you

    Brian

    My code is …

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

    Dim dtAcType As New DataTable

    Dim da1 As New SqlDataAdapter(“SELECT AcType, AcTypeName FROM dbo.fntvGetAcTypesList(NULL, NULL) WHERE AcType IN (0, 1, 2, 4, 5);”, DbConnection)

    da1.Fill(dtAcType)

    Dim dtSubAc As New DataTable

    Dim da2 As New SqlDataAdapter(“SELECT SubAc, ShortTypeName FROM dbo.fntvGetAcTypesList(NULL, NULL) WHERE AcType = 0”, DbConnection)

    da2.Fill(dtSubAc)

    With Me.C1FlexGrid1

    .Cols(1).Name = “ID”

    .Cols(2).Name = “AcType”

    .Cols(3).Name = “SubAc”

    .Cols(4).Name = “TranDate”

    .Cols(“AcType”).DataMap = New MultiColumnDictionary(dtAcType, “AcType”, {“AcType”, “AcTypeName”}, 0)

    .Cols(“SubAc”).DataMap = New MultiColumnDictionary(dtSubAc, “SubAc”, {“SubAc”, “ShortTypeName”}, 0)

    End With

    End Sub

    Private Sub C1FlexGrid1_StartEdit(sender As Object, e As RowColEventArgs) Handles C1FlexGrid1.StartEdit

    If Me.C1FlexGrid1.Cols(e.Col).Name = “SubAc” Then

    If Not Me.C1FlexGrid1(e.Row, “AcType”) Is Nothing Then

    Dim da2 As New SqlDataAdapter("SELECT SubAc, ShortTypeName FROM dbo.fntvGetAcTypesList(NULL, NULL) WHERE AcType = " & Me.C1FlexGrid1(e.Row, “AcType”), DbConnection)

    Dim dtSubAc As New DataTable

    da2.Fill(dtSubAc)

    Me.C1FlexGrid1.Cols(“SubAc”).DataMap = New MultiColumnDictionary(dtSubAc, “SubAc”, {“SubAc”, “ShortTypeName”}, 0)

    End If

    End If

    End Sub

  • Posted 1 August 2019, 11:41 pm EST

    Hello,

    Your interpretation of other rows go blank is correct because when you set the datamap for column it compares all the cell values of that column with the key value of datamap. That is why in your case other cells of that Column goes blank.

    To achieve this task you need to use the DataMap property of the CellStyle class and assign the style to the current editing cell.

    In place of setting datamap for column in StartEdit event use the code snippet given below :

    Dim cs As CellStyle = C1FlexGrid1.Styles.Add("")
    cs.DataMap = New MultiColumnDictionary(dtSubAc, "SubAc", {"SubAc", "ShortTypeName"}, 0)
    C1FlexGrid1.SetCellStyle(e.Row, e.Col, cs)
    

    Please go through the attached sample demonstrating the same.

    Thanks and Regards,

    Prabhat Sharma.

    MultiColumnDictionaryDataMapDemo.zip

  • Posted 2 August 2019, 12:39 am EST

    Oh, ok. I don’t yet understand how using the CellStyle on the current cell but I will look thru the example and see.

    Thanks again.

    Brian

  • Posted 2 August 2019, 3:59 am EST

    Mr Sharma,

    That solution was so simple it was like magic. Still don’t understand why it works though, would never have thought of that.

    Thanks

    Brian

  • Posted 2 August 2019, 5:16 am EST

    Mr Sharma,

    One more question,

    How can I make the dropdownlist to show when I tab into a cell that has one?

    Regards

    Brian Morris

  • Posted 2 August 2019, 2:11 pm EST

    Mr Sharma,

    I am noticing that when I load back data from the db into the grid the values in the .Cols(“AcType”) may not be 0 which is the value I assumed when I setup the datatable to get the datamap values for the .Cols(“SubAc”). So you see can get blanks in the .Cols(“SubAc”) until you actually click in the cell. Is it that I should essentially go thru the whole Cols(“SubAc”) force the StartEdit() code to execute for each cell? Is there a better way?

  • Posted 4 August 2019, 9:41 pm EST

    Hello,

    1 : When setting DataMap through CellStyle for particular cell will not affect values in the other cell of that column but if you set it for whole column it will compare each and every cell value of that column with the key values in the DataMap. If not found, it goes blank.

    2 : To make the dropdownlist show when tabbed into a cell, you need to handle RowColChange event of FlexGrid as given in code snippet below :

    Private Sub C1FlexGrid1_RowColChange(sender As Object, e As EventArgs) Handles C1FlexGrid1.RowColChange
            If C1FlexGrid1.Col = 1 OrElse (C1FlexGrid1.Col = 2 AndAlso C1FlexGrid1(C1FlexGrid1.Row, 1) IsNot Nothing) Then
                C1FlexGrid1.StartEditing()
                Dim comboBox As ComboBox = C1FlexGrid1.Editor
                comboBox.DroppedDown = True
            End If
    End Sub
    

    3 : You can use the BeforeEdit event of FlexGrid to set the DataMap of the corresponding cell instead of using StartEdit event. By using this event you need not to force the StartEdit() code to show the DataMap dropdown on the particular cell.

    Please go through the sample where I have implemented the above explained scenario.

    If my understanding is incorrect, please provide a stripped down sample or modify the attached sample replicating the issue.

    Thanks and Regards,

    Prabhat Sharma.

    MultiColumnDictionaryDataMapDemo.zip

  • Posted 5 August 2019, 2:19 am EST

    Mr Sharma,

    1. Ah, yes, I understand thanks for the explanation.
    2. Ok, I’ll try that.
    3. Let me double-check what I was seeing.

      Regards

      Brian Morris
  • Posted 5 August 2019, 4:00 am EST

    Mr Sharma,

    2. Yes, drops down automatically now.

    Is it possible to disable the up/down arrows from changing rows, so that you must TAB/ShiftTAB thru the row instead ?

    1. With regard to the initial load and the datamap showing blanks I think I see the difference in what you did. You set the datamap to include ALL the car models and only restricted by brand in the StartEdit. I restricted in the initial load as well. Works perfectly now. I better understand why now so just have to make sure there are no bad side-effects with how my db is structured.

      Thanks

      Brian Morris
  • Posted 5 August 2019, 4:28 pm EST

    Hello,

    First of all thanks for the information.

    To disable the up/down arrow keys, you need to handle KeyDown event as given in code snippet below :

    Private Sub C1FlexGrid1_KeyDown(sender As Object, e As KeyEventArgs) Handles C1FlexGrid1.KeyDown
        If e.KeyCode = Keys.Down OrElse e.KeyCode = Keys.Up Then
           e.SuppressKeyPress = True
        End If
    End Sub
    

    To use the Tab/Shift+Tab works like up/down arrow keys, you need to set the KeyActionTab property of FlexGrid as given below :

    C1FlexGrid1.KeyActionTab = KeyActionEnum.MoveDown
    

    I have modified this scenario in the attached sample, please have a look.

    I hope it helps.

    Thanks and Regards,

    Prabhat Sharma.

    MultiColumnDictionaryDataMapDemo.zip

  • Posted 6 August 2019, 12:25 am EST

    Cool, thanks.

    Brian Morris

  • Posted 2 August 2020, 5:50 am EST

    Very important: Columms name in NEW MULTICOLUMNDICTIONARY are

    cASE sENSITIVE.

      Dim Mc As MultiColumnDictionary
                Mc = New MultiColumnDictionary(DtEnlace, "Subfamilia", {"Subfamilia", "NombreSubFamilia", "NombreFamilia"}, 0)
    
                FlexArticulos.Cols("Cod_Subfamilia").DataMap = Mc
    

    or you get a error ‘nothing’

  • Posted 3 August 2020, 10:06 pm EST

    Hi Roberto Alonso,

    Thank you for this notification. We have escalated this to the developers.

    [Internal Tracking ID: 456108]

    Regards,

    Prabhat Sharma.

Need extra support?

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

Learn More

Forum Channels