This is a migrated thread and some comments may be shown as answers.

GridViewColumnGroup

9 Answers 353 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sangeetha
Top achievements
Rank 1
Sangeetha asked on 06 Oct 2010, 11:25 AM

In Winforms, Gridview, I have a table with 6 columns.

First 2 columns are not grouped. Next 3 columns are grouped and last one column is not grouped.

Is it possible to create such partially grouped gridview? I do not want empty text for the ungrouped columns.

That is 3,4,5 columns alone must have column header using GridViewColumnGroup.

9 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 06 Oct 2010, 12:28 PM
Hi, 

Could you post a screenshot of what you have / want for clarity please? 
Thanks
Richard
0
Sangeetha
Top achievements
Rank 1
answered on 06 Oct 2010, 12:53 PM

I am not able to post a screen shot, but it is something like this,

totally 6 columns say, A, B, C, D, E, F.

C, D, E columns alone have their header divided in to two horizontally.  That is they have a common header.
0
Richard Slade
Top achievements
Rank 2
answered on 06 Oct 2010, 05:27 PM
Hi, 

What I think you need is Column Group View. This allows you to group columns with a common header. 
See the following links
http://www.telerik.com/help/winforms/overview2.html


An example would be to load in your data, then 
' Me.ColumnGroupsViewDefinition() is your own method to return a View Definition
Me.GridView.ViewDefinition = Me.ColumnGroupsViewDefinition()

Private Function ColumnGroupsViewDefinition() As ColumnGroupsViewDefinition
 
    Dim columnGroupsView As ColumnGroupsViewDefinition
 
    Dim columnGroupRowSample1 As GridViewColumnGroupRow
    Dim columnGroupRowSample2 As GridViewColumnGroupRow
    Dim columnGroupRowSample3 As GridViewColumnGroupRow
 
    Dim columnGroupSample1 As GridViewColumnGroup
    Dim columnGroupSample2 As GridViewColumnGroup
    Dim columnGroupSample3 As GridViewColumnGroup
 
    columnGroupRowSample1 = New GridViewColumnGroupRow()
    With columnGroupRowSample1.Columns
        .Add(Me.GridView.Columns("A"))
        .Add(Me.GridView.Columns("B"))
        .Add(Me.GridView.Columns("C"))
    End With
 
    columnGroupRowSample2 = New GridViewColumnGroupRow()
    With columnGroupRowSample2.Columns
        .Add(Me.GridView.Columns("D"))
        .Add(Me.GridView.Columns("E"))
        .Add(Me.GridView.Columns("F"))
    End With
 
    columnGroupRowSample3 = New GridViewColumnGroupRow()
    With columnGroupRowSample3.Columns
        .Add(Me.GridView.Columns("G"))
        .Add(Me.GridView.Columns("H"))
        .Add(Me.GridView.Columns("I"))
    End With
 
    columnGroupSample1 = New GridViewColumnGroup("Sample1")
    columnGroupSample1.Rows.Add(columnGroupRowSample1)
 
    columnGroupSample2 = New GridViewColumnGroup("Sample2")
    columnGroupSample2.Rows.Add(columnGroupRowSample2)
 
    columnGroupSample3 = New GridViewColumnGroup("Sample3")
    columnGroupSample3.Rows.Add(columnGroupRowSample3)
 
    columnGroupsView = New ColumnGroupsViewDefinition()
    columnGroupsView.ColumnGroups.Add(columnGroupSample1)
    columnGroupsView.ColumnGroups.Add(columnGroupSample2)
    columnGroupsView.ColumnGroups.Add(columnGroupSample3)
 
    Return columnGroupsView
End Function

hope that helps
Richard
0
Sangeetha
Top achievements
Rank 1
answered on 08 Oct 2010, 05:20 AM


Thanks for your reply. This sample has 3 column group headers Sample1, Sample2, Sample3.
But I need only column group header "Sample2". The first 3 & last 3 columns should not have column group headers.


Alternately i tried to set the group header text as empty, For example,

GridViewColumnGroup

 

columnGroup1 = new GridViewColumnGroup();

 

columnGroupsView.ColumnGroups.Add(columnGroup1);
columnGroup1.Text = "";

But there is no border separating the columngroups sample1, sample 2 & sample 3.
That is they tend to appear continuous without line separating the column group names.

 

0
Emanuel Varga
Top achievements
Rank 1
answered on 08 Oct 2010, 06:50 AM
Hello Sangeetha,

I think you are looking for HTML views, not group views, you can take a look at this documentation article, or in the Demos application, under GridView -> Columns -> Grid Views  and select HTML view.

I think it will cover your scenario perfectly,

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
Sangeetha
Top achievements
Rank 1
answered on 08 Oct 2010, 07:16 AM
It is not html view. It is group view since I need to group 3 columns alone with one header.
0
Emanuel Varga
Top achievements
Rank 1
answered on 08 Oct 2010, 07:21 AM
Hello Sangeetha,

From what i understood you need some columns to NOT belong to any group, if you are using Column Group View you cannot accomplish this, please take a look at what i suggested, using HTML views you can accomplish everything you can using Column Group View, and you can even use HTML syntax to create the table header if you want to.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
Richard Slade
Top achievements
Rank 2
answered on 08 Oct 2010, 07:30 AM
Hi Sangeetha,

You said. "The first 3 & last 3 columns should not have column group headers."
In that case, you can leave columns A,B,C with the original headers, put D,E,F with a common header, and leave G,H,I with the original headers. For example:

Private Function ColumnGroupsViewDefinition() As ColumnGroupsViewDefinition
   
    Dim columnGroupsView As ColumnGroupsViewDefinition
   
    Dim columnGroupRowSample2 As GridViewColumnGroupRow
   
    Dim columnGroupSample2 As GridViewColumnGroup
   
    columnGroupRowSample2 = New GridViewColumnGroupRow()
    With columnGroupRowSample2.Columns
        .Add(Me.GridView.Columns("D"))
        .Add(Me.GridView.Columns("E"))
        .Add(Me.GridView.Columns("F"))
    End With
   
  
    columnGroupSample2 = New GridViewColumnGroup("Sample2")
    columnGroupSample2.Rows.Add(columnGroupRowSample2)
  
   
    columnGroupsView = New ColumnGroupsViewDefinition()
    columnGroupsView.ColumnGroups.Add(columnGroupSample2)
   
    Return columnGroupsView
End Function

Alternatvly, you could use HTML Views too. Hope that helps
Richard
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 08 Oct 2010, 12:21 PM
Hi Sangeetha, 
Apologies. You DO need an HTML view. 

If you want some columns to have a common header and others not to, then HTML View will support this perfectly. 
Richard
Tags
GridView
Asked by
Sangeetha
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Sangeetha
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Share this question
or