Solved

Help with displaing multiple rows in a cell of a DataGridView

Posted on 2014-03-04
9
1,429 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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
 

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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