• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1727
  • Last Modified:

Help with displaing multiple rows in a cell of a DataGridView

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
vcharles
Asked:
vcharles
1 Solution
 
Minh Võ CôngCommented:
Can you explain in more detail what you want?
0
 
Kishan ZunjareCommented:
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
 
vcharlesAuthor Commented:
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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
Jacques Bourgeois (James Burger)Commented:
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
 
vcharlesAuthor Commented:
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
 
Jacques Bourgeois (James Burger)Commented:
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
 
vcharlesAuthor Commented:
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
 
Jacques Bourgeois (James Burger)Commented:
Note that if you fill the grid in Form_Load, you must add that code before you fill it up.
0
 
vcharlesAuthor Commented:
Hi,

It works.

Thank You.

Victor
0

Featured Post

Independent Software Vendors: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now