Solved

Datagridview - Merge row

Posted on 2006-11-08
5
2,779 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now