?
Solved

Help with displaing multiple rows in a cell of a DataGridView

Posted on 2014-03-04
9
Medium Priority
?
1,621 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

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