英文:
Fixed Total Row When Sorting DataGridview
问题
我有一个名为ADVANCEDDATAGRIDVIEW的DataGridView。
请查看此链接https://www.nuget.org/packages/DG.AdvancedDataGridView。
好的?
现在我从DATATABLE填充了这个DGV。
这是第一段代码:DT已经包含数据。
With Form1.AdvancedDataGridView1
.DataSource = DT
Form1.BindingSource1.DataSource = .DataSource
End With
所以现在这个DGV有来自DT的数据,并且我从DATAGRIDVIEW.DataSource中添加了一个来自工具箱的BindingSource。
AdvancedDataGridView已经有了类似Microsoft Office中Excel的筛选图标。
但为了使其工作,您必须在FilteringChange事件中编写以下代码。
Private Sub AdvancedDataGridView1_FilterStringChanged(sender As Object, e As EventArgs) Handles AdvancedDataGridView1.FilterStringChanged
BindingSource1.Filter = AdvancedDataGridView1.FilterString
End Sub
所以现在我向DT中添加了一行,就像DT.rows.add()这样。
所以我通过列的总和来填充这一行。
如您所见,当我使用它时,上面有一个筛选图标,并且可以像Microsoft Excel中一样筛选数据,它工作得很好。
但是在筛选后,最后一行(总行)消失了。
我对我的英语和描述感到抱歉。
这是我尝试过的。
Private Sub AdvancedDataGridView1_FilterStringChanged(sender As Object, e As EventArgs) Handles AdvancedDataGridView1.FilterStringChanged
Dim A, B As String
A = CStr(AdvancedDataGridView1.FilterString)
B = A & " Or ItemName = 'total'"
BindingSource1.Filter = B
End Sub
兄弟,非常感谢@dr.null,这对我有用,我需要更改什么吗?
这里是排序问题。
Private Sub AdvancedDataGridView1_SortStringChanged(sender As Object, e As EventArgs) Handles AdvancedDataGridView1.SortStringChanged
BindingSource1.Sort = AdvancedDataGridView1.SortString
BindingSource1.Sort = "Sorting Asc"
End Sub
在这段代码中,我添加了一个名为"Sorting"的列,并将所有列的值都设置为0,除了总行,我将其设置为1。
现在这段代码对我来说不起作用,有什么可以尝试的吗?
英文:
I have DATAGRIDVIEW CALLED ADVANCEDDATAGRIDVIEW
see this link
https://www.nuget.org/packages/DG.AdvancedDataGridView
okay ?
now I Filled this DGV FROM DATATABLE
Here the First Code : DT is A DATATABLE already has data
With Form1.AdvancedDataGridView1
.DataSource = DT
Form1.BindingSource1.DataSource = .DataSource : Endwith
So now this DGV HAS DATA FROM DT
And I added BindingSource FROM TOOLBOX into Form1 And i Filled it From DATAGRIDVIEW.DataSource
The AdvancedDataGridview has already Filters Icons Like excel in Microsoft Office
But to make it Work You have to Write this Code in FilteringChange Event like this
Private Sub AdvancedDataGridView1_FilterStringChanged(sender As Object, e As EventArgs) Handles AdvancedDataGridView1.FilterStringChanged
BindingSource1.Filter = AdvancedDataGridView1.FilterString : End SUB
So now Added row in DT as like DT.rows.add() like this
so this ROW i Filled it By sum Of columns
ok.. Now look at the Image and see DGV NOW
So As You see there is Filter Icon up Wheni use it And filter data Like excel in MS its work fine
But the last row ( TOTAL ROW ) become Not exist after Filtering
I am sorry for my bad English and description
THIS IS WHAT I Have Tried
Private Sub AdvancedDataGridView1_FilterStringChanged(sender As Object, e As EventArgs) Handles AdvancedDataGridView1.FilterStringChanged
Dim A, B As String
A = CStr(AdvancedDataGridView1.FilterString)
B = A & " Or ItemName = 'total'"
BindingSource1.Filter = B
Bro Thank you Very Much @dr.null
this work fine with me should I change anything ?
Here sorting issue
Private Sub AdvancedDataGridView1_SortStringChanged(sender As Object, e As EventArgs) Handles AdvancedDataGridView1.SortStringChanged
BindingSource1.Sort = AdvancedDataGridView1.SortString
BindingSource1.Sort = "Sorting Asc"
on this code i added column named "Sorting" and i put all Column value = 0 except total row i made it = 1
now this code dose not work with me correctly
have Anything to try ?
答案1
得分: 1
我通过 @dr.null 解决了
Private Sub AdvancedDataGridView1_FilterStringChanged(sender As Object, e As EventArgs) Handles AdvancedDataGridView1.FilterStringChanged
Dim A As String = AdvancedDataGridView1.FilterString
Dim B As String = If(String.IsNullOrEmpty(A), A, A & " 或 ItemName = 'total'")
BindingSource1.Filter = B
英文:
I solved by @dr.null
Private Sub AdvancedDataGridView1_FilterStringChanged(sender As Object, e As EventArgs) Handles AdvancedDataGridView1.FilterStringChanged
Dim A As String = AdvancedDataGridView1.FilterString
Dim B As String = If(String.IsNullOrEmpty(A), A, A & " Or ItemName = 'total'")
BindingSource1.Filter = B
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论