{"id":5914,"date":"2014-04-09T01:54:47","date_gmt":"2014-04-09T01:54:47","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/09\/how-can-i-merge-cell-of-a-gridview-having-same-value-at-runtime-in-vb-net-collection-of-common-programming-errors\/"},"modified":"2014-04-09T01:54:47","modified_gmt":"2014-04-09T01:54:47","slug":"how-can-i-merge-cell-of-a-gridview-having-same-value-at-runtime-in-vb-net-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/09\/how-can-i-merge-cell-of-a-gridview-having-same-value-at-runtime-in-vb-net-collection-of-common-programming-errors\/","title":{"rendered":"how can i merge cell of a gridview having same value at runtime in vb.net .-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn<\/p>\n<p>Hello,<\/p>\n<p>i want to show the schedule in a grid.In that grid there is a column\u00a0 &#8216;Time&#8217; with the cells like 8am,8:30:am&#8230;&#8230;9pm. and other column have employee name so if an employee has task from 8 am to 10 am then i make those cells in red color with employee name. now whats happening is, from 8am to 10 am all the cells are showing that employee name but i want to merge them into one and make the employee name at center.<\/p>\n<p>Please help me out.<\/p>\n<p>Thanks &amp; Regards,<\/p>\n<p>Sonal<\/p>\n<\/li>\n<li>\n<h3>25 Answers<\/h3>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn1<\/p>\n<p>Hi,<\/p>\n<p>i recreated the scenario in VB.NET language with DataTable as datasource. Please follow the code.It is working fine.<\/p>\n<pre>Imports System.Data\n\nPublic Class Form1\n    Dim dt As New DataTable\n\n    Public Sub New()\n\n        ' This call is required by the designer.\n        InitializeComponent()\n        dt.Columns.Add(New DataColumn(\"Column1\"))\n        dt.Columns.Add(New DataColumn(\"Column2\"))\n\n        Dim row1 As DataRow = dt.NewRow()\n        row1(\"Column1\") = \"A\"\n        row1(\"Column2\") = \"Green\"\n        dt.Rows.Add(row1)\n\n        Dim row2 As DataRow = dt.NewRow()\n        row2(\"Column1\") = \"A\"\n        row2(\"Column2\") = \"Pink\"\n        dt.Rows.Add(row2)\n\n        Dim row3 As DataRow = dt.NewRow()\n        row3(\"Column1\") = \"B\"\n        row3(\"Column2\") = \"Red\"\n        dt.Rows.Add(row3)\n\n        Dim row4 As DataRow = dt.NewRow()\n        row4(\"Column1\") = \"C\"\n        row4(\"Column2\") = \"Blue\"\n        dt.Rows.Add(row4)\n\n        Dim row5 As DataRow = dt.NewRow()\n        row5(\"Column1\") = \"D\"\n        row5(\"Column2\") = \"Green\"\n        dt.Rows.Add(row5)\n\n        Dim row6 As DataRow = dt.NewRow()\n        row6(\"Column1\") = \"D\"\n        row6(\"Column2\") = \"Blue\"\n        dt.Rows.Add(row6)\n\n        Dim row7 As DataRow = dt.NewRow()\n        row7(\"Column1\") = \"E\"\n        row7(\"Column2\") = \"Green\"\n        dt.Rows.Add(row7)\n\n        DataGridView1.DataSource = dt\n\n    End Sub\n\n\n    Private Sub DataGridView1_CellPainting(sender As System.Object, e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting\n\n        If e.RowIndex = 0 Then\n\n            If (DataGridView1.Rows(e.RowIndex).Cells(0).Value.ToString() = DataGridView1.Rows(e.RowIndex + 1).Cells(0).Value.ToString()) Then\n                If (e.ColumnIndex = 0) Then\n                    e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None\n                End If\n            End If\n\n        End If\n\n        If e.RowIndex &gt; 0 Then\n            If e.RowIndex &lt; DataGridView1.Rows.Count - 2 Then\n                If (DataGridView1.Rows(e.RowIndex - 1).Cells(0).Value.ToString() = DataGridView1.Rows(e.RowIndex).Cells(0).Value.ToString()) Then\n                    If (e.ColumnIndex = 0) Then\n                        e.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.None\n                    End If\n                End If\n\n                If (DataGridView1.Rows(e.RowIndex).Cells(0).Value.ToString() = DataGridView1.Rows(e.RowIndex + 1).Cells(0).Value.ToString()) Then\n                    If (e.ColumnIndex = 0) Then\n                        e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None\n                    End If\n                End If\n            End If\n\n        End If\n\n\n    End Sub\nEnd Class\n\n\n<\/pre>\n<p>\nLet me know if your issue persists. As you said you can remove duplicate text , so just let me know if you were able to do that!<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn2<\/p>\n<p>Hi Sonal,<\/p>\n<p>Thanks for your patience.<\/p>\n<p>I thought it will be a better way to remove repeated entry in the DataSource itself and with some little modifications you can achieve your requirement.<\/p>\n<p>So, before binding i modified the data table like this :<\/p>\n<pre> Dim prev As String = dt.Rows(0)(0).ToString()\n\n        For i = 1 To dt.Rows.Count - 1\n\n            If dt.Rows(i)(0).ToString() = prev Then\n                dt.Rows(i)(0) = \"\"\n            Else\n                prev = dt.Rows(i)(0).ToString()\n            End If\n\n        Next\n        DataGridView1.DataSource = dt<\/pre>\n<p>After modification, i have done some changes in the CellPainting event, so please follow the code, you will achieve your requirement:<\/p>\n<pre> Private Sub DataGridView1_CellPainting(sender As System.Object, e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting\n\n        If e.RowIndex &gt; 0 Then\n            If e.RowIndex &lt; DataGridView1.Rows.Count - 2 Then\n                If DataGridView1.Rows(e.RowIndex + 1).Cells(0).Value.ToString() = \"\" Then\n                    If (e.ColumnIndex = 0) Then\n                        e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None\n                    End If\n                End If\n\n                If DataGridView1.Rows(e.RowIndex).Cells(0).Value.ToString() = \"\" Then\n                    If (e.ColumnIndex = 0) Then\n                        e.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.None\n                    End If\n                End If\n            End If\n        End If\n\n        If e.RowIndex = 0 Then\n            If DataGridView1.Rows(e.RowIndex + 1).Cells(0).Value.ToString() = \"\" Then\n                If (e.ColumnIndex = 0) Then\n                    e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None\n                End If\n            End If\n        End If\n    End Sub<\/pre>\n<p>\nHope this helps. Let me know if you are still in problem.<\/p>\n<p>One good question is equivalent to ten best answers.<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn3<\/p>\n<p>Hello,<\/p>\n<p>Not completely clear but is this what you want i.e. remove repeating data?<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/social.msdn.microsoft.com\/Forums\/getfile\/222697\" \/><\/p>\n<p>If so then add the following DataGridView to your project, use it as any DataGridView i.e. DataGridView1.DataSource = SomeDataTable.<\/p>\n<pre>''' \n''' Original author\n''' http:\/\/social.msdn.microsoft.com\/Forums\/en-US\/winformsdatacontrols\/thread\/a44622c0-74e1-463b-97b9-27b87513747e#faq8\n''' \n''' \n''' Original code was in C Sharp, I converted and tweaked some code\n''' which did not compile under VB.NET\n''' \nPublic Class GroupByGrid\n    Inherits DataGridView\n    Protected Overrides Sub OnCellFormatting(ByVal args As DataGridViewCellFormattingEventArgs)\n        MyBase.OnCellFormatting(args)\n        ' First row always displays\n        If args.RowIndex = 0 Then\n            Return\n        End If\n        If IsRepeatedCellValue(args.RowIndex, args.ColumnIndex) Then\n            args.Value = String.Empty\n            args.FormattingApplied = True\n        End If\n    End Sub\n    Private Function IsRepeatedCellValue(ByVal rowIndex As Integer, ByVal colIndex As Integer) As Boolean\n        Dim currCell As DataGridViewCell = Rows(rowIndex).Cells(colIndex)\n        Dim prevCell As DataGridViewCell = Rows(rowIndex - 1).Cells(colIndex)\n        If (currCell.Value Is prevCell.Value) OrElse (currCell.Value IsNot Nothing AndAlso prevCell.Value IsNot Nothing AndAlso currCell.Value.ToString() = prevCell.Value.ToString()) Then\n            Return True\n        Else\n            Return False\n        End If\n    End Function\n    Protected Overrides Sub OnCellPainting(ByVal args As DataGridViewCellPaintingEventArgs)\n        MyBase.OnCellPainting(args)\n        args.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None\n        ' Ignore column and row headers and first row\n        If args.RowIndex &lt; 1 OrElse args.ColumnIndex &lt; 0 Then\n            Return\n        End If\n        If IsRepeatedCellValue(args.RowIndex, args.ColumnIndex) Then\n            args.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.None\n        Else\n            args.AdvancedBorderStyle.Top = AdvancedCellBorderStyle.Top\n        End If\n    End Sub\nEnd Class<\/pre>\n<p><\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn4<\/p>\n<p>Hi Shyam,<\/p>\n<p>It is a window form Desktop Project.<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn5<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn6<\/p>\n<p>Yes, I have gone through the below link, but i didnt find it helpful.<\/p>\n<p>http:\/\/www.dotnetspider.com\/resources\/4644-Merge-columns-DataGridView-Excel-Spread.aspx<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn7<\/p>\n<p>Hi, follow the code to get your resolution.<\/p>\n<p>dataGridView1 is added in designer.<\/p>\n<pre>namespace WindowsFormsApplication1\n{\n    public partial class Form1 : Form\n    {\n        List li = new List();\n        public Form1()\n        {\n            InitializeComponent();\n           \n            li.Add(new X() { Column1 = \"A\", Column2 =\"Green\" });\n            li.Add(new X() { Column1 = \"A\", Column2 = \"Red\" });\n            li.Add(new X() { Column1 = \"B\", Column2 = \"Green\" });\n            li.Add(new X() { Column1 = \"C\", Column2 = \"Blue\" });\n            li.Add(new X() { Column1 = \"E\", Column2 = \"Pink\" });\n            li.Add(new X() { Column1 = \"E\", Column2 = \"Green\" });\n            li.Add(new X() { Column1 = \"F\", Column2 = \"Black\" });\n\n\n            dataGridView1.DataSource = li;\n            dataGridView1.CellPainting += new DataGridViewCellPaintingEventHandler(dataGridView1_CellPainting);\n        }\n\n       \n\n        void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)\n        {\n            if (e.RowIndex == 0)\n            {\n                if (dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString() == dataGridView1.Rows[e.RowIndex +1].Cells[0].Value.ToString())\n                {\n                    if (e.ColumnIndex == 0)\n                    {\n                        e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None;\n                        \n                    }\n                }\n            }\n            \n            if (e.RowIndex &gt;0)\n            {\n                if (dataGridView1.Rows[e.RowIndex - 1].Cells[0].Value.ToString() == dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString())\n                {\n                    if (e.ColumnIndex == 0)\n                    {\n                        e.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.None;\n                       \n                    }\n                }\n\n                if (e.RowIndex &lt; dataGridView1.Rows.Count - 1)\n                {\n                    if (dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString() == dataGridView1.Rows[e.RowIndex + 1].Cells[0].Value.ToString())\n                    {\n                        if (e.ColumnIndex == 0)\n                        {\n                            e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None;\n                           \n                        }\n                    }\n                }\n            }\n        }\n    }\n\n    public class X\n    {\n        public string Column1 { get; set; }\n        public string Column2 { get; set; }\n    }\n}<\/pre>\n<p>Hope this may help.<\/p>\n<p>One good question is equivalent to ten best answers.<\/p>\n<p><\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn8<\/p>\n<p>Thanks Shyam.<\/p>\n<p>But i have used same code before but it didnt work.datagridview cells border style remain same.<\/p>\n<p><\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn9 Oh yea. I only thought to merge the borders. I left to take only one data per merged cell.Ok let me try.<br \/>\nDid the borders are merged from your side for repeated data?<\/p>\n<p>One good question is equivalent to ten best answers.<\/p>\n<p><\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn10<\/p>\n<p>Nope, data i can handle but the issue is with the border only. its nt getting merge because i guess border style isnt getting change.<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn11 Hi, have you copy-paste my whole code and taken DataGridView in design ?<\/p>\n<p>Here from my side everything works fine. All matching cells border are merged from my side.<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn12<\/p>\n<p>I copied what\u00a0 i needed like i copied the whole code from datagridview CellPainting event and pasted it into Datagridview cellpainting event in my code.<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn13<\/p>\n<p>I am binding Datagridview to a datatable. i am using the above code in the DataGridView_CellPainting event :<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 For i As Integer = 1 To dgvScheduler.Columns.Count &#8211; 1 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 If e.RowIndex = 0 Then \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 If dgvScheduler.Rows(e.RowIndex).Cells(i).Value.ToString() = dgvScheduler.Rows(e.RowIndex + 1).Cells(i).Value.ToString() Then \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 If e.ColumnIndex = 0 Then \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 End If \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 End If \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 End If \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 If e.RowIndex &gt; 0 Then \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 If dgvScheduler.Rows(e.RowIndex &#8211; 1).Cells(i).Value.ToString() = dgvScheduler.Rows(e.RowIndex).Cells(i).Value.ToString() Then \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 If e.ColumnIndex = 0 Then \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 e.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.None \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 End If \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 End If \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 If e.RowIndex &lt; dgvScheduler.Rows.Count &#8211; 1 Then \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 If dgvScheduler.Rows(e.RowIndex).Cells(i).Value.ToString() = dgvScheduler.Rows(e.RowIndex + 1).Cells(i).Value.ToString() Then \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 If e.ColumnIndex = 0 Then \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 End If \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 End If \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 End If \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 End If \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Next<\/p>\n<p><\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn14<\/p>\n<p>i created a separate application and used your code it worked absolutely fine. then why not in my code.<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn15<\/p>\n<p>Hi,<\/p>\n<p>i recreated the scenario in VB.NET language with DataTable as datasource. Please follow the code.It is working fine.<\/p>\n<pre>Imports System.Data\n\nPublic Class Form1\n    Dim dt As New DataTable\n\n    Public Sub New()\n\n        ' This call is required by the designer.\n        InitializeComponent()\n        dt.Columns.Add(New DataColumn(\"Column1\"))\n        dt.Columns.Add(New DataColumn(\"Column2\"))\n\n        Dim row1 As DataRow = dt.NewRow()\n        row1(\"Column1\") = \"A\"\n        row1(\"Column2\") = \"Green\"\n        dt.Rows.Add(row1)\n\n        Dim row2 As DataRow = dt.NewRow()\n        row2(\"Column1\") = \"A\"\n        row2(\"Column2\") = \"Pink\"\n        dt.Rows.Add(row2)\n\n        Dim row3 As DataRow = dt.NewRow()\n        row3(\"Column1\") = \"B\"\n        row3(\"Column2\") = \"Red\"\n        dt.Rows.Add(row3)\n\n        Dim row4 As DataRow = dt.NewRow()\n        row4(\"Column1\") = \"C\"\n        row4(\"Column2\") = \"Blue\"\n        dt.Rows.Add(row4)\n\n        Dim row5 As DataRow = dt.NewRow()\n        row5(\"Column1\") = \"D\"\n        row5(\"Column2\") = \"Green\"\n        dt.Rows.Add(row5)\n\n        Dim row6 As DataRow = dt.NewRow()\n        row6(\"Column1\") = \"D\"\n        row6(\"Column2\") = \"Blue\"\n        dt.Rows.Add(row6)\n\n        Dim row7 As DataRow = dt.NewRow()\n        row7(\"Column1\") = \"E\"\n        row7(\"Column2\") = \"Green\"\n        dt.Rows.Add(row7)\n\n        DataGridView1.DataSource = dt\n\n    End Sub\n\n\n    Private Sub DataGridView1_CellPainting(sender As System.Object, e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting\n\n        If e.RowIndex = 0 Then\n\n            If (DataGridView1.Rows(e.RowIndex).Cells(0).Value.ToString() = DataGridView1.Rows(e.RowIndex + 1).Cells(0).Value.ToString()) Then\n                If (e.ColumnIndex = 0) Then\n                    e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None\n                End If\n            End If\n\n        End If\n\n        If e.RowIndex &gt; 0 Then\n            If e.RowIndex &lt; DataGridView1.Rows.Count - 2 Then\n                If (DataGridView1.Rows(e.RowIndex - 1).Cells(0).Value.ToString() = DataGridView1.Rows(e.RowIndex).Cells(0).Value.ToString()) Then\n                    If (e.ColumnIndex = 0) Then\n                        e.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.None\n                    End If\n                End If\n\n                If (DataGridView1.Rows(e.RowIndex).Cells(0).Value.ToString() = DataGridView1.Rows(e.RowIndex + 1).Cells(0).Value.ToString()) Then\n                    If (e.ColumnIndex = 0) Then\n                        e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None\n                    End If\n                End If\n            End If\n\n        End If\n\n\n    End Sub\nEnd Class\n\n\n<\/pre>\n<p>\nLet me know if your issue persists. As you said you can remove duplicate text , so just let me know if you were able to do that!<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn16<\/p>\n<p>HI,<\/p>\n<p>you need to modify second If condition. Get\u00a0 the code with appropiate If condition as per the Code.<\/p>\n<p>Different languages different constructs!<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn17<\/p>\n<p>Seems its working. Can u pls tell me how to merge data now?<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn18<\/p>\n<blockquote><p>Seems its working. Can u pls tell me how to merge data now?<\/p><\/blockquote>\n<p>Even if we remove the duplicate Text, i fear is it possible to Show the Text Vertically\u00a0Center ?<\/p>\n<p>Since unlike HTML table, here we did not have CellSpan or ColumnSpan ? So how your cells Text will be vertically center aligned ?<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn19<\/p>\n<p>yeah true. but its no use if i don&#8217;t remove the duplicate Text. Can we show the text at TOP ?<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn20<\/p>\n<blockquote><p>yeah true. but its no use if i don&#8217;t remove the duplicate Text. Can we show the text at TOP ?<\/p><\/blockquote>\n<p>\nYes, that we can try \ud83d\ude42<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn21<\/p>\n<p>ok, then lets try \ud83d\ude42<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn22<\/p>\n<p>Hi Sonal,<\/p>\n<p>Thanks for your patience.<\/p>\n<p>I thought it will be a better way to remove repeated entry in the DataSource itself and with some little modifications you can achieve your requirement.<\/p>\n<p>So, before binding i modified the data table like this :<\/p>\n<pre> Dim prev As String = dt.Rows(0)(0).ToString()\n\n        For i = 1 To dt.Rows.Count - 1\n\n            If dt.Rows(i)(0).ToString() = prev Then\n                dt.Rows(i)(0) = \"\"\n            Else\n                prev = dt.Rows(i)(0).ToString()\n            End If\n\n        Next\n        DataGridView1.DataSource = dt<\/pre>\n<p>After modification, i have done some changes in the CellPainting event, so please follow the code, you will achieve your requirement:<\/p>\n<pre> Private Sub DataGridView1_CellPainting(sender As System.Object, e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting\n\n        If e.RowIndex &gt; 0 Then\n            If e.RowIndex &lt; DataGridView1.Rows.Count - 2 Then\n                If DataGridView1.Rows(e.RowIndex + 1).Cells(0).Value.ToString() = \"\" Then\n                    If (e.ColumnIndex = 0) Then\n                        e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None\n                    End If\n                End If\n\n                If DataGridView1.Rows(e.RowIndex).Cells(0).Value.ToString() = \"\" Then\n                    If (e.ColumnIndex = 0) Then\n                        e.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.None\n                    End If\n                End If\n            End If\n        End If\n\n        If e.RowIndex = 0 Then\n            If DataGridView1.Rows(e.RowIndex + 1).Cells(0).Value.ToString() = \"\" Then\n                If (e.ColumnIndex = 0) Then\n                    e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None\n                End If\n            End If\n        End If\n    End Sub<\/pre>\n<p>\nHope this helps. Let me know if you are still in problem.<\/p>\n<p>One good question is equivalent to ten best answers.<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn23<\/p>\n<p>Hello,<\/p>\n<p>Not completely clear but is this what you want i.e. remove repeating data?<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/social.msdn.microsoft.com\/Forums\/getfile\/222697\" \/><\/p>\n<p>If so then add the following DataGridView to your project, use it as any DataGridView i.e. DataGridView1.DataSource = SomeDataTable.<\/p>\n<pre>''' \n''' Original author\n''' http:\/\/social.msdn.microsoft.com\/Forums\/en-US\/winformsdatacontrols\/thread\/a44622c0-74e1-463b-97b9-27b87513747e#faq8\n''' \n''' \n''' Original code was in C Sharp, I converted and tweaked some code\n''' which did not compile under VB.NET\n''' \nPublic Class GroupByGrid\n    Inherits DataGridView\n    Protected Overrides Sub OnCellFormatting(ByVal args As DataGridViewCellFormattingEventArgs)\n        MyBase.OnCellFormatting(args)\n        ' First row always displays\n        If args.RowIndex = 0 Then\n            Return\n        End If\n        If IsRepeatedCellValue(args.RowIndex, args.ColumnIndex) Then\n            args.Value = String.Empty\n            args.FormattingApplied = True\n        End If\n    End Sub\n    Private Function IsRepeatedCellValue(ByVal rowIndex As Integer, ByVal colIndex As Integer) As Boolean\n        Dim currCell As DataGridViewCell = Rows(rowIndex).Cells(colIndex)\n        Dim prevCell As DataGridViewCell = Rows(rowIndex - 1).Cells(colIndex)\n        If (currCell.Value Is prevCell.Value) OrElse (currCell.Value IsNot Nothing AndAlso prevCell.Value IsNot Nothing AndAlso currCell.Value.ToString() = prevCell.Value.ToString()) Then\n            Return True\n        Else\n            Return False\n        End If\n    End Function\n    Protected Overrides Sub OnCellPainting(ByVal args As DataGridViewCellPaintingEventArgs)\n        MyBase.OnCellPainting(args)\n        args.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None\n        ' Ignore column and row headers and first row\n        If args.RowIndex &lt; 1 OrElse args.ColumnIndex &lt; 0 Then\n            Return\n        End If\n        If IsRepeatedCellValue(args.RowIndex, args.ColumnIndex) Then\n            args.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.None\n        Else\n            args.AdvancedBorderStyle.Top = AdvancedCellBorderStyle.Top\n        End If\n    End Sub\nEnd Class<\/pre>\n<p><\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn24<\/p>\n<p>Hi Shyam,<\/p>\n<p>Thank you so much.<\/p>\n<p>I really appreciated the way u helped me out and understood what i wanted.Finally i achieved exactly what i wanted \ud83d\ude42<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn25<\/p>\n<p>Hello Kevin,<\/p>\n<p>Thanks alot.<\/p>\n<p>your code is working perfectly and it helped me \ud83d\ude42<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>msdn Hello, i want to show the schedule in a grid.In that grid there is a column\u00a0 &#8216;Time&#8217; with the cells like 8am,8:30:am&#8230;&#8230;9pm. and other column have employee name so if an employee has task from 8 am to 10 am then i make those cells in red color with employee name. now whats happening [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5914","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5914","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5914"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5914\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}