Solved

Help with displaing multiple rows in a cell of a DataGridView

Posted on 2014-03-04
9
1,366 Views
Last Modified: 2014-03-05
Hi,

Is it possible to have multiple rows of data in a cell of a DataGridView? This is a Windows app (vb.net) Visual Studio 2010.


Victor
0
Comment
Question by:vcharles
9 Comments
 
LVL 15

Expert Comment

by:Minh Võ Công
ID: 39905399
Can you explain in more detail what you want?
0
 
LVL 7

Expert Comment

by:Kishan Zunjare
ID: 39905426
Instead of showing multiple rows in single cell, here you can use nested DataGridView means GridView inside GridView.


Bellow are some of examples of nested gridview.
http://www.dotnetfox.com/articles/multilevel-nested-gridview-in-Asp-Net-using-C-Sharp-1012.aspx
http://www.codeproject.com/Articles/685079/Nested-GridView-in-ASP-NET-using-Csharp
0
 

Author Comment

by:vcharles
ID: 39905432
The data is to big to fit in one row, I'm trying to add multiple rows instead of viewing all the data when I place the cursor on the cell.
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 39905683
You cannot put 2 rows in the same cell, but you can set the height to a bigger value and force the text to wrap with the following:

            DataGridView1.RowTemplate.Height = 30
            DataGridView1.Rows(0).Height = 30
            DataGridView1.RowsDefaultCellStyle.WrapMode = DataGridViewTriState.True

RowTemplate.Height will change the height of new rows, but does not handle the first row, because it is already created when you enter Form_Load. You must thus also set the height of the first row.

Change the value from 30 to whatever does the trick for you.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:vcharles
ID: 39907247
Hi,

I'm afraid the cells height did not change, below is the code I'm using, any ideas why it is not working?

If Form1.SCREEN1.Checked = True Then

            Dim SearchCriteria As String = "NSC IN (" & xyz & " )"
        
            Dim FilteredDTA As DataTable
            Dim DVA As New DataView(dtsetLinkSCREEN1.Tables(0), SearchCriteria, Nothing, DataViewRowState.CurrentRows)
            FilteredDTA = DVA.ToTable
            If FilteredDTA.Rows.Count > 0 Then
                Me.C1Screen1.DataSource = FilteredDTA
                Dim i As Integer
                i = 0

                For i = 1 To 9
                    Me.C1SCREEN1.Columns(i).Visible = False
                Next
                For i = 25 To 50
                    Me.C1SCREEN1.Columns(i).Visible = False
                Next

                'Change headers text color
                For row As Integer = 0 To C1SCREEN1.Rows.Count - 1
                    For col As Integer = 0 To C1SCREEN1.Columns.Count - 1
                        If CStr(C1SCREEN1.Item(col, row).Value) = "13" Or CStr(C1SCREEN1.Item(col, row).Value) = "15" Then

                            C1SCREEN1.Columns(col).HeaderCell.Style.BackColor = Color.Red
                            C1SCREEN1.Columns(col).HeaderCell.Style.ForeColor = Color.White
                            Exit Sub
                        End If
                    Next
                Next

                
                'wrap text in cell  (Not Working)
                C1SCREEN1.RowTemplate.Height = 100
                C1SCREEN1.Rows(0).Height = 100
                C1SCREEN1.RowsDefaultCellStyle.WrapMode = DataGridViewTriState.True



            Else
                MsgBox("No Records Found")

            End If



        End If

Open in new window


Thanks,

Victor
0
 
LVL 40
ID: 39907332
I told you to do that in Form_Load.

The Rowtemplate is used on new rows, so you need to set it before the rows are added to the grid, so that code should be used before you fill the grid with data if you want all the rows to be the same height.

If you want to do it only on specific rows, then simply call C1SCREEN1.Rows(x).Height = 100
, where x is the number of the row.
0
 

Author Comment

by:vcharles
ID: 39907473
I tried it on Form Load before I sent you the code but
the application did not display any data on the grid, will try again when back in the office.
Thanks.
0
 
LVL 40
ID: 39907702
Note that if you fill the grid in Form_Load, you must add that code before you fill it up.
0
 

Author Comment

by:vcharles
ID: 39907981
Hi,

It works.

Thank You.

Victor
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
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: …

747 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

12 Experts available now in Live!

Get 1:1 Help Now