This is a migrated thread and some comments may be shown as answers.

GridView Cell Merge using Cell Border Style

2 Answers 243 Views
GridView
This is a migrated thread and some comments may be shown as answers.
HyunBae
Top achievements
Rank 1
HyunBae asked on 03 Sep 2012, 03:15 AM

In winforms, I try to merge cell using cell border style.
There are some problem in cell border color.

attached file is screen shot.
plz help me

        private void BtnDel_Click(object sender, EventArgs e)
        {
            MergeCell(GvMain, new int[] { 1, 2, 3, 4, 5 });
        }

        private void MergeCell(RadGridView gv, int [] idx)
        {
            GridViewRowInfo Prev = null;
           
            foreach (GridViewRowInfo item in gv.Rows)
            {
                if (Prev != null)
                {
                    string s1 = string.Empty;
                    string s2 = string.Empty;

                    foreach (int i in idx)
                    {
                        GridViewCellInfo c1 = Prev.Cells[i];
                        GridViewCellInfo c2 = item.Cells[i];

                        //s1 += "|" + (c1 != null && c1.Value != null ? c1.Value.ToString() : string.Empty);
                        //s2 += "|" + (c2 != null && c2.Value != null ? c2.Value.ToString() : string.Empty);
                        s1 = (c1 != null && c1.Value != null ? c1.Value.ToString() : string.Empty);
                        s2 = (c2 != null && c2.Value != null ? c2.Value.ToString() : string.Empty);

                        if (s1 == s2)
                        {
                            //c2.Value = string.Empty;
                            c2.Style.ForeColor = Color.Transparent;

                            //c2.Style.DrawBorder = true;
                            c2.Style.CustomizeBorder = true;
                            c2.Style.BorderTopWidth = 0;
                            //c2.Style.BorderTopColor = Color.Transparent;
                        }
                        else
                        {
                            //c2.Style.CustomizeBorder = false;
                            Prev = item;

                            break;
                        }
                    }
                }
                else
                {
                    Prev = item;
                }
            }
        }

2 Answers, 1 is accepted

Sort by
0
Accepted
Anton
Telerik team
answered on 05 Sep 2012, 12:37 PM
Hi HyunBae,

Thank you for contacting Telerik Support.

Here is the modified version of your code that will resolve your issue:
private void MergeCell(RadGridView gv, int[] idx)
{
    GridViewRowInfo Prev = null;
    foreach (GridViewRowInfo item in gv.Rows)
    {
        if (Prev != null)
        {
            string s1 = string.Empty;
            string s2 = string.Empty;
            foreach (int i in idx)
            {
                GridViewCellInfo c1 = Prev.Cells[i];
                GridViewCellInfo c2 = item.Cells[i];
                s1 = (c1 != null && c1.Value != null ? c1.Value.ToString() : string.Empty);
                s2 = (c2 != null && c2.Value != null ? c2.Value.ToString() : string.Empty);
                c1.Style.CustomizeBorder = true;
                c1.Style.BorderBoxStyle = Telerik.WinControls.BorderBoxStyle.FourBorders;
                c1.Style.BorderLeftColor = Color.FromArgb(209, 225, 245);
                c1.Style.BorderRightColor = Color.FromArgb(209, 225, 245);
                c2.Style.CustomizeBorder = true;
                c2.Style.BorderBoxStyle = Telerik.WinControls.BorderBoxStyle.FourBorders;
                c2.Style.BorderLeftColor = Color.FromArgb(209, 225, 245);
                c2.Style.BorderRightColor = Color.FromArgb(209, 225, 245);
                c2.Style.BorderTopColor = Color.FromArgb(209, 225, 245);
                c2.Style.BorderBottomColor = Color.FromArgb(209, 225, 245);
                if (c1.Style.BorderTopColor != Color.Transparent)
                {
                    c1.Style.BorderTopColor = Color.FromArgb(209, 225, 245);
                }
                if (s1 == s2)
                {
                    c1.Style.BorderBottomColor = Color.Transparent;
                    c2.Style.BorderTopColor = Color.Transparent;
                    c2.Style.ForeColor = Color.Transparent;
                }
                else
                {
                    Prev = item;
                    break;
                }
            }
        }
        else
        {
            Prev = item;
        }
    }
}

Attached is a sample project that comprises the code above. I hope this helps.

Should you have any other questions, I will be glad to assist you.

Kind regards,
Anton
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
HyunBae
Top achievements
Rank 1
answered on 08 Sep 2012, 01:58 AM
Thanks for your support.
As you mentioned, I resolve previous problem and also understand your control concept for border control.
Thanks again.
Tags
GridView
Asked by
HyunBae
Top achievements
Rank 1
Answers by
Anton
Telerik team
HyunBae
Top achievements
Rank 1
Share this question
or