如何使用GROUPING在gridview中显示数据 [英] How to display the data in gridview using GROUPING
问题描述
大家好...
i我在vb.net做报告管理系统,我想在gridview中显示以下类型的数据...
这是我的MS Access数据库:
______________________________________________________________________________________________
INVOICE ID |客户ID |客户名称|付款日期|总金额| BALANCE AMOUNT
______________________________________________________________________________________________
1 | 1 | RAVI | 1-1-2013 | 5000 | 3000
1 | 1 | RAVI | 2-2-2013 | 5000 | 1000
2 | 2 | KUMAR | 5-1-2013 | 10000 | 5000
3 | 3 | RAJ | 3-1-2013 | 2000年| 0
2 | 2 | KUMAR | 8-2-2013 | 10000 | 2000
4 | 1 | RAVI | 10-5-2013 | 5000 | 2000
5 | 3 | RAJ | 12-8-2013 | 8000 | 4000
----------------------------------------- -------------------------------------------------- ----
我想在gridview中显示如下数据:
______________________________________________________________________________________________
INVOICEID | CLIENTID |客户名称|付款日期|总金额| BALANCE AMOUNT
______________________________________________________________________________________________
1 | 1 | RAVI | 1-1-2013 | 5000 | 3000
------------ | 2-2-2013 | 5000 | 1000
4 | | 10-2-2013 | 5000 | 2000
----------------------------------------- -------------------------------------------------- ---
2 | 2 | KUMAR | 5-1-2013 | 10000 | 5000
------------ | 8-1-2013 | 10000 | 2000
----------------------------------------- -------------------------------------------------- ---
3 | 3 | RAJ | 3-1-2013 | 2000年| 0
5 --------- | 12-8-2013 | 8000 | 0
______________________________________________________________________________________________
PLS发送您的想法....
如果你在asp工作看看:
http://stackoverflow.com/questions/4076148/put-multiple-data-in-one-cell-asp -net-vb-net [ ^ ]
和
< a href =http://stackoverflow.com/questions/15099320/group-merge-multiple-records-as-one-gridview-row> http://stackoverflow.com/questions/15099320/group-merge-multiple -records-as-one-gridview-row [ ^ ]
我自己解决了这个问题,我的代码如下:
私有 Sub DataGridView1_CellPainting(发件人 As 对象,e As DataGridViewCellPaintingEventArgs)句柄 DataGridView1.CellPainting
如果 e.ColumnIndex = 2 并且还 e.RowIndex<> -1 然后
' e.ColumnIndex = (2)是分组字段的列索引。
使用 gridBrush 作为 Brush = 新 SolidBrush( Me .DataGridView1.GridColor),backColorBrush As Brush = 新 SolidBrush(e.CellStyle.BackColor)
使用 gridLinePen As Pen = 新笔(gridBrush)
e.Graphics.FillRectangle(backColorBrush,e.CellBounds)
如果 e.RowIndex< DataGridView1.Rows.Count - 2 AndAlso DataGridView1.Rows(e.RowIndex + 1 )。单元格(e.ColumnIndex).Value.ToString()<> e.Value.ToString()然后
e.Graphics.DrawLine(gridLinePen,e.CellBounds.Left,e.CellBounds.Bottom - 1 ,e.CellBounds.Right - 1 ,e.CellBounds.Bottom - 1 )
结束 如果
e.Graphics.DrawLine( gridLinePen,e.CellBounds.Right - 1 ,e.CellBounds.Top,e.CellBounds.Right - 1 ,e.CellBounds.Bottom)
如果 不 e.Value 没什么 然后
如果 e.RowIndex> 0 AndAlso DataGridView1.Rows(e.RowIndex - 1 )。单元格(e.ColumnIndex).Value.ToString()= e.Value.ToString()然后
Else
e.Graphics.DrawString( CType (e.Value, String ),e.CellStyle.Font,Brushes.Black,e.CellBounds.X + 2 ,e.CellBounds.Y + 5 ,StringFormat.GenericDefault)
结束 如果
结束 如果
e.Handled = True
结束 使用
结束 使用
结束 如果
结束 Sub 跨度>
Hi All...
i am doing report management system in vb.net,i want to display the data in gridview the following type...
This is my MS Access Database:
______________________________________________________________________________________________
INVOICE ID | CLIENT ID | CLIENT NAME |PAYMENT DATE | TOTAL AMOUNT | BALANCE AMOUNT
______________________________________________________________________________________________
1 | 1 | RAVI | 1-1-2013 | 5000 | 3000
1 | 1 | RAVI | 2-2-2013 | 5000 | 1000
2 | 2 | KUMAR | 5-1-2013 | 10000 | 5000
3 | 3 | RAJ | 3-1-2013 | 2000 | 0
2 | 2 | KUMAR | 8-2-2013 | 10000 | 2000
4 | 1 | RAVI | 10-5-2013 | 5000 | 2000
5 | 3 | RAJ | 12-8-2013 | 8000 | 4000
-----------------------------------------------------------------------------------------------
I Want to be display this data in gridview like below:
______________________________________________________________________________________________
INVOICEID | CLIENTID | CLIENT NAME | PAYMENT DATE | TOTAL AMOUNT | BALANCE AMOUNT
______________________________________________________________________________________________
1 | 1 | RAVI | 1-1-2013 | 5000 | 3000
------------| 2-2-2013 | 5000 | 1000
4 | | 10-2-2013 | 5000 | 2000
----------------------------------------------------------------------------------------------
2 | 2 | KUMAR | 5-1-2013 | 10000 | 5000
------------ | 8-1-2013 | 10000 | 2000
----------------------------------------------------------------------------------------------
3 | 3 | RAJ | 3-1-2013 | 2000 | 0
5 --------- | 12-8-2013 | 8000 | 0
______________________________________________________________________________________________
PLS send your ideas....
if you work in asp look at this:
http://stackoverflow.com/questions/4076148/put-multiple-data-in-one-cell-asp-net-vb-net[^]
And
http://stackoverflow.com/questions/15099320/group-merge-multiple-records-as-one-gridview-row[^]
I am solve this problem myself, My code is below:
Private Sub DataGridView1_CellPainting(sender As Object, e As DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting If e.ColumnIndex = 2 AndAlso e.RowIndex <> -1 Then 'e.ColumnIndex = (2) is a column index of your grouping field. Using gridBrush As Brush = New SolidBrush(Me.DataGridView1.GridColor), backColorBrush As Brush = New SolidBrush(e.CellStyle.BackColor) Using gridLinePen As Pen = New Pen(gridBrush) e.Graphics.FillRectangle(backColorBrush, e.CellBounds) If e.RowIndex < DataGridView1.Rows.Count - 2 AndAlso DataGridView1.Rows(e.RowIndex + 1).Cells(e.ColumnIndex).Value.ToString() <> e.Value.ToString() Then e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, e.CellBounds.Bottom - 1) End If e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, e.CellBounds.Top, e.CellBounds.Right - 1, e.CellBounds.Bottom) If Not e.Value Is Nothing Then If e.RowIndex > 0 AndAlso DataGridView1.Rows(e.RowIndex - 1).Cells(e.ColumnIndex).Value.ToString() = e.Value.ToString() Then Else e.Graphics.DrawString(CType(e.Value, String), e.CellStyle.Font, Brushes.Black, e.CellBounds.X + 2, e.CellBounds.Y + 5, StringFormat.GenericDefault) End If End If e.Handled = True End Using End Using End If End Sub
这篇关于如何使用GROUPING在gridview中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!