Solved

Datagridview - Merge row

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

680 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