Solved

Datagridview - Merge row

Posted on 2006-11-08
5
2,784 Views
Last Modified: 2008-02-07
I have a set of data like below:

ItemNo   Month               SalesAmount
1            11                    1000
1            10                    2000
1            09                    3000
2            11                    4000
2            10                    5000
3            11                    6000


Is there any method  in datagridview to display like below:

ItemNo   Month               SalesAmount
1            11                    1000
              10                    2000
              09                    3000
2            11                    4000
              10                    5000
3            11                    6000

Hope I don't have to manipulate records one by one that not what I want!!!

Thanks a lot.

0
Comment
Question by:tora111
5 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 250 total points
ID: 17905120
I don't think this is possible, at least on the sort of simple approach you are looking for.  

What you need to remember is that a DataGridView is a mechanism for displaying and editing data which is in fact held elsewhere - in the datatable (or whatever) that is its .DataSource.  Each row in the DataGridView represents a record in the datasource.  If a record includes a value in a particular field that value will be shown in the corresponding column in the DataGridView.  Although you can choose to display, or not to display, or to re-order the display of, particular fields/columns the facility to do this is column based: that is, it applies to all rows.  So, without some (fairly complex, I think) self-coding, your ItemNo will either display or it won't display.

I'll be happy to be told I'm wrong on this: it looks like a fairly useful facility.  But, as I say, I don't think it exists in the control as it stands.

Roger
0
 
LVL 3

Assisted Solution

by:vsvb
vsvb earned 250 total points
ID: 17906119
This is not elegent solution but as so far DataGrid not provide such utility
we have to write some custom code

        Dim d As Integer
        Dim kd As Integer
        kd = -1
        Dim cell As DataGridViewCell
        For d = 0 To DataGridView1.Rows.Count - 1
            If kd <> DataGridView1.Rows(d).Cells(0).Value Then  
                kd = DataGridView1.Rows(d).Cells(0).Value
            Else
                cell = DataGridView1.Rows(d).Cells(0)
                cell.Style.ForeColor = Color.White
                cell.ReadOnly = True
            End If
        Next

you have to write some code when cell is select .. then it shows item in selected cell ( DarkBlue/ white)
-vsvb
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VS.net 2010 11 48
VB.net Progress Bar - Maximum Value too large 2 15
Visual studio 2015 1 21
Get month and date in a format 4 31
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question