Solved

Help with displaing multiple rows in a cell of a DataGridView

Posted on 2014-03-04
9
1,391 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb.net 2 37
How to deploy to IIS 7 on 2008R2 server with DUO 2-step login? 2 32
Name space syntax error 12 39
SQL Exceptions 3 36
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

932 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

13 Experts available now in Live!

Get 1:1 Help Now