Binding C1FlexGrid to a Data Source From EF6

Posted by: castingdouala on 4 May 2018, 8:35 am EST

    • Post Options:
    • Link

    Posted 4 May 2018, 8:35 am EST

    Hello Team,

    I have a database of more than 100000 Customers, each customer having a corresponding Orders. I wish to display this information as a treeview/hierachical (With search, filter and sorting). I have read the samples but i could not find it useful as my data is fecthed using EF6.

    Any Help on how to tackle this? Thanks.

  • Posted 4 May 2018, 8:47 am EST

    I forgot to say i use and Database first approach. If it helps…

  • Posted 7 May 2018, 9:34 am EST

    Hello,

    Just to confirm did you see the product sample Orders-EF-WinForms? Though it uses general DataGridView, you should still be able to get some help from it.

    Thanks,

    Ruchir

  • Posted 7 May 2018, 10:03 am EST

    Hello Ruchir,

    No. Can i have a sample?

  • Posted 9 May 2018, 9:41 am EST

    Hi,

    You find C1DataSource related samples installed at \Documents\ComponentOne Samples\WinForms\C1DataSource\CS. Also, the sample I am referring to shows how to use C1DataSource along with DataGridView and should help you get along with using C1DataSource.

    Regards,

  • Posted 10 May 2018, 9:11 pm EST

    Hello I’m also working with EF6 and am trying to load into a flexgrid with predefined columns. Will loading from an IQueryable result work with a C1FlexGrid or does it require a DataGridView?

    This isn’t working for me:

    Dim pats = From p In context.Patients Select New PatientGridFields With {.PatientID = p.Id, .FullName = p.LastName & ", " & p.FirstName, .MRN = p.MRN, .Gender = p.Gender}
    
    PatientGrid.DataSource = pats
    
    

    Thanks

  • Posted 11 May 2018, 5:15 am EST

    Hi,

    I doubt, for binding C1Flexgrid to EF6 in code, please refer to the product sample TutorialsWinForms-C1FlexGrid (installed at \Documents\ComponentOne Samples\WinForms\C1DataSource\CS )and navigate to its ‘DataSources in Code’ part to see how that works.

    Thanks,

    Ruchir

  • Posted 16 May 2018, 7:59 pm EST

    Thanks I was using public fields rather than properties, so the columns weren’t loading.

    I’m not sure if there’s a preferred way to load into a grid with existing columns, but I wrote a VB function for that:

    
        Public Sub LoadFlexGrid(ByVal grid As C1FlexGrid, ByVal list As IEnumerable, Optional useExistingColumns As Boolean = True)
            Dim initProps As Boolean
            Dim colProps() As System.Reflection.PropertyInfo
            Dim curRow As Row
    
            If grid Is Nothing Or list Is Nothing Then
                Exit Sub
            End If      
            If Not useExistingColumns Then
                grid.DataSource = list
                Exit Sub
            End If
    
            grid.Redraw = False
            grid.Rows.Count = 1
            For Each item In list
                If Not initProps Then
                    ReDim colProps(0 To grid.Cols.Count - 1)
                    For j = 0 To grid.Cols.Count - 1
                        colProps(j) = item.GetType.GetProperty(grid.Cols(j).Name, System.Reflection.BindingFlags.Public Or System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.IgnoreCase)
                    Next
                    initProps = True
                End If
    
                curRow = grid.Rows.Add
                For j = 0 To grid.Cols.Count - 1
                    If colProps(j) IsNot Nothing Then
                        curRow(j) = colProps(j).GetValue(item)
                    End If
                Next
            Next
            grid.Redraw = True
        End Sub
    
    
  • Posted 17 May 2018, 12:34 am EST

    Thank you for sharing the cause of the trouble for you and it’s resolution. I hope your solution will help others in the community.

    Thanks,

    Ruchir

Need extra support?

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

Learn More

Forum Channels