Skip to main content Skip to footer

Operational Dashboard in C1FlexGrid for Winforms

This blog deals with yet another utility implementation of C1FlexGrid for Winforms. Two most important features offered by this grid are Filtering and Sorting. On applying any of these functionality on the grid, the visual changes are easily noticeable. However, there is a certain set of information that cannot be determined by simply looking at the resultant grid. You need to explicitly display the information, after writing some code to retrieve those values. This blog guides how to retrieve the following information when Filtering and Sorting operations are performed on C1Flexgrid:

Filtering

A. Type of Filtering : Single/Multi Column This value tells you whether the filtering is applied on a single column or on multiple columns. B. Number of the Filtered Columns This will list the total number of filtered columns C. Name of the Columns Filtered This will list the names of all the filtered columns D. Total number of Rows This will show the total number of rows in C1Flexgrid E. Count of Filtered rows Ideally, if you wish to retrieve the Row count value after filtering, you will use the property 'Rows.Count'. However, this will give you the total rows present in C1FlexGrid (without filtering). This code implementation below helps to get the number of visible rows after filtering. F. Actual Index of the Selected Cell It gives you the original Cell index as in the DataSource of the **C1Flexgrid. G. Visible Index of the Selected Cell** It gives you the Cell index as visible after filtering You may refer to the following code to implement the above discussed features :


    Private Sub C1FlexGrid1_AfterFilter(ByVal sender As Object, ByVal e As System.EventArgs) Handles C1FlexGrid1.AfterFilter  

        Name_FilteredCol.Text = ""  
        Filtering_Type.Text = "NA"  
        count_filter = 0  
        ivisible = 0  

        'getting the count of visible rows  
        With C1FlexGrid1  
            For i = 1 To .Rows.Count - 1 ' Beginning from 1 (0 is Header)  
                If .Rows(i).IsVisible Then  
                    ivisible += 1  
                End If  
            Next  
        End With  

        'check if filtering applied and get the name and total number of filtered columns  
        With C1FlexGrid1  
            For i = 1 To .Cols.Count - 1  
                If .Cols(i).Filter.IsActive Then  
                    count_filter += 1  
                    If count_filter > 1 Then  
                        Name_FilteredCol.Text += ", "  
                    End If  
                    Name_FilteredCol.Text += C1FlexGrid1.Cols(i).Name  
                End If  
            Next  
        End With  

        If count_filter = 0 Then  
            Filtering_Type.Text = "NA"  
            Name_FilteredCol.Text = "NA"  
            C1SplitterPanel1.Text = "Filtering : NA"  
            Number_FilteredCol.Text = "NA"  
        ElseIf count_filter = 1 Then  
            Filtering_Type.Text = "Single Column"  
            C1SplitterPanel1.Text = "Filtering : Applied"  
            Number\_FilteredCol.Text = count\_filter.ToString  
        ElseIf count_filter > 1 Then  
            Filtering_Type.Text = "Multi Column"  
            C1SplitterPanel1.Text = "Filtering : Applied"  
            Number\_FilteredCol.Text = count\_filter.ToString  
        End If  

        Count_TotalRows.Text = (C1FlexGrid1.Rows.Count - 1).ToString  
        Count_FilteredRows.Text = ivisible.ToString  

    End Sub  

    Private Sub C1FlexGrid1_AfterSelChange(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.RangeEventArgs) Handles C1FlexGrid1.AfterSelChange  
        e.Cancel = True  
        CellIndex_Actual.Text = "Cell(" & e.NewRange.r1.ToString & "," & e.NewRange.c1.ToString & ")"  
        ivisible = 0  

        'getting the visible index of the selected cell  
        With C1FlexGrid1  
            For i = 1 To .Rows.Count - 1 ' Beginning from 1 (0 is Header)  
                If .Rows(i).IsVisible Then  
                    ivisible += 1  
                    If .Rows(i).Selected = True Then  
                        CellIndex_Visible.Text = "Cell(" & ivisible.ToString & "," & C1FlexGrid1.ColSel.ToString & ")"  
                    End If  
                End If  
            Next  
        End With  
    End Sub

Sorting

A. Type of Sorting : Single/Multi Column This value tells you whether the sorting is applied on a single column or on multiple columns. B. Number of the Sorted Columns This will list the total number of sorted columns C. Name of the Sorted Columns This will list the names of all the sorted columns D. Sort Order of the Columns This will list the SortOrder applied on each of the sorted columns. This listing would be in sync with the list of the names of the sorted columns. Refer to the following code to implement the above discussed features :


    Private Sub C1FlexGrid1_AfterSort(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.SortColEventArgs) Handles C1FlexGrid1.AfterSort  
        count_sort = 0  
        Name_SortedCol.Text = ""  
        SortOrder_Col.Text = ""  

        'check if sorting is applied and get the count of the sorted columns  
        'also getting the list of the names of the sorted columns  
        With C1FlexGrid1  
            For i = 1 To .Cols.Count - 1 ' Beginning from 1 (0 is Header)  
                If .Cols(i).Sort = C1.Win.C1FlexGrid.SortFlags.Ascending Then  
                    count_sort += 1  
                    If count_sort > 1 Then  
                        Name_SortedCol.Text += ", "  
                        SortOrder_Col.Text += ","  
                    End If  
                    Name_SortedCol.Text += C1FlexGrid1.Cols(i).Name  
                    SortOrder_Col.Text += "Ascending"  
                ElseIf C1FlexGrid1.Cols(i).Sort = C1.Win.C1FlexGrid.SortFlags.Descending Then  
                    count_sort += 1  
                    If count_sort > 1 Then  
                        Name_SortedCol.Text += ", "  
                        SortOrder_Col.Text += ","  
                    End If  
                    Name_SortedCol.Text += C1FlexGrid1.Cols(i).Name  
                    SortOrder_Col.Text += "Descending"  
                End If  
            Next  
        End With  

        If count_sort = 0 Then  
            Sorting_Type.Text = ""  
        ElseIf count_sort = 1 Then  
            Sorting_Type.Text = "Single Column"  
        ElseIf count_sort > 1 Then  
            Sorting_Type.Text = "Multi Column"  
        End If  

        Numbr\_SortedCol.Text = count\_sort.ToString  

        If count_sort > 0 Then  
            C1SplitterPanel2.Text = "Sorting : Applied"  
        Else  
            C1SplitterPanel2.Text = "Sorting : NA"  
        End If  
    End Sub

Implementing the above code blocks would give the following output : Download the attached samples VB/C# for complete implementation.

This blog deals with yet another utility implementation of C1FlexGrid. Two most important features offered by this grid are Filtering and Sorting. On applying any of this functionality on the grid, the visual changes are easily noticeable. However, there is a certain set of information that can not be determined by simply looking at the resultant grid as there isn't any way to directly access the same. You need to explicitly write some code to retreive the values of it. This blog guides how to retrieve the following information when Filtering ansd Sorting operations are performed in C1FlexGrid : 1. Filtering : A. Type of Filtering B. Number of the Filtedred Columns C. Name of the Filtered Columns D. Total number of Rows E. Count of the Filtered Rows F. Actual Index of the Selected Cell G. Visible Index of the Selected Cell 2. Sorting : A. Type of Sorted B. numbder of the Sorted Columns C. Name of the Sorted Columns D. Sort Order of the Columns Let's begin with the implementation of the same. Filtering : A. Type of Filtering : Single/Multi Column This value tells whether the filtering is applied on a single column or on multiple columns. B. Number of the Filtedred Columns This will list the total number of filtered columns C. Name of the Columns Filtered This will list the names of all the filtered columns D. Total number of Rows This will show the number of the total rows in c1Flexgrid E. Count of Filtered rows Ideally, when we retrieve the value of 'RowsCount', we get the number of the total rows present in C1FlexGrid. However, the code implementation mentioned below helps us get the number of visible rows after filtering. F. Actual Index of the Selected Cell It gives us the cellindex as in the datasource of the C1Flexgrid G. Visible Index of the Selected Cell It gives us the cellindex as visible to us after filtering You may refer to the following code to implement the above discussed features : Private Sub C1FlexGrid1_AfterFilter(ByVal sender As Object, ByVal e As System.EventArgs) Handles C1FlexGrid1.AfterFilter Name_FilteredCol.Text = "" Filtering_Type.Text = "NA" count_filter = 0 ivisible = 0 With C1FlexGrid1 For i = 1 To .Rows.Count - 1 ' Beginning from 1 (0 is Header) If .Rows(i).IsVisible Then ivisible += 1 End If Next End With With C1FlexGrid1 For i = 1 To .Cols.Count - 1 If .Cols(i).Filter.IsActive Then count_filter += 1 If count_filter > 1 Then Name_FilteredCol.Text += ", " End If Name_FilteredCol.Text += C1FlexGrid1.Cols(i).Name End If Next End With If count_filter = 0 Then Filtering_Type.Text = "NA" Name_FilteredCol.Text = "NA" C1SplitterPanel1.Text = "Filtering : NA" Number_FilteredCol.Text = "NA" ElseIf count_filter = 1 Then Filtering_Type.Text = "Single Column" C1SplitterPanel1.Text = "Filtering : Applied" Number_FilteredCol.Text = count_filter.ToString ElseIf count_filter > 1 Then Filtering_Type.Text = "Multi Column" C1SplitterPanel1.Text = "Filtering : Applied" Number_FilteredCol.Text = count_filter.ToString End If Count_TotalRows.Text = (C1FlexGrid1.Rows.Count - 1).ToString Count_FilteredRows.Text = ivisible.ToString End Sub Private Sub C1FlexGrid1_AfterSelChange(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.RangeEventArgs) Handles C1FlexGrid1.AfterSelChange e.Cancel = True CellIndex_Actual.Text = "Cell(" & e.NewRange.r1.ToString & "," & e.NewRange.c1.ToString & ")" ivisible = 0 With C1FlexGrid1 For i = 1 To .Rows.Count - 1 ' Beginning from 1 (0 is Header) If .Rows(i).IsVisible Then ivisible += 1 If .Rows(i).Selected = True Then CellIndex_Visible.Text = "Cell(" & ivisible.ToString & "," & C1FlexGrid1.ColSel.ToString & ")" End If End If Next End With End Sub 2. Sorting : A. Type of Sorting : Single/Multi Column This value tells whether the sorting is applied on a single column or on multiple columns. B. Number of the Sorted Columns This will list the total number of sorted columns C. Name of the Sorted Columns This will list the names of all the sorted columns D. Sort Order of the Columns This will list the sort order applied on each of the sorted column. The listing would be in sync with the list of the names of the sorted columns. You may refer to the following code to implement the above discussed features : count_sort = 0 Name_SortedCol.Text = "" SortOrder_Col.Text = "" With C1FlexGrid1 For i = 1 To .Cols.Count - 1 ' Beginning from 1 (0 is Header) If .Cols(i).Sort = C1.Win.C1FlexGrid.SortFlags.Ascending Then count_sort += 1 If count_sort > 1 Then Name_SortedCol.Text += ", " SortOrder_Col.Text += "," End If Name_SortedCol.Text += C1FlexGrid1.Cols(i).Name SortOrder_Col.Text += "Ascending" ElseIf C1FlexGrid1.Cols(i).Sort = C1.Win.C1FlexGrid.SortFlags.Descending Then count_sort += 1 If count_sort > 1 Then Name_SortedCol.Text += ", " SortOrder_Col.Text += "," End If Name_SortedCol.Text += C1FlexGrid1.Cols(i).Name SortOrder_Col.Text += "Descending" End If Next End With If count_sort = 0 Then Sorting_Type.Text = "" ElseIf count_sort = 1 Then Sorting_Type.Text = "Single Column" ElseIf count_sort > 1 Then Sorting_Type.Text = "Multi Column" End If Numbr_SortedCol.Text = count_sort.ToString If count_sort > 0 Then C1SplitterPanel2.Text = "Sorting : Applied" Else C1SplitterPanel2.Text = "Sorting : NA" End If

MESCIUS inc.

comments powered by Disqus