Mangesh
2016-02-25T05:27:47Z
Hi,

I have an application that it would look easier to separate Rows by a line, possibly by changing the color of horizontal border.

How to do that ?

I do not want to use Frozen Area Property.

Thanks
-Mangesh
Igor/10Tec
2016-02-25T07:21:09Z
You can draw your own border in the CustomDrawCellBackground or CustomDrawCellForeground event. In fact, you can replace the default drawing of the cell background, or add your custom line to the standard cell contents in one of these events.

For more info, see the Custom Draw Cells topic in the Cell Appearance and Behavior section in the manual.
Mangesh
2016-02-29T11:27:20Z
Thanks for reply.

I tried this solution. It adds horizontal line.
But it also resets the other formatting applied to the cells in that row.


I can share sample code if required.

-Mangesh
Igor/10Tec
2016-03-01T07:12:56Z
Yes, sure, you can share your source code for the further consideration.

If possible, show us a picture of what you need to implement.
Mangesh
2016-03-01T13:22:26Z
Sample.png

Click to View Image146 View(s)




Hi,

Thanks for quick reply.

Please see the screenshot.

Here I have created a grid with some default values

On form load I have initialized a grid as-

// Form load
private void Form1_Load(object sender, EventArgs e)
        {
            InitializeGrid();

            iGrid1.Rows[1].CellStyle = new iGCellStyle();

            //set custom draw flags
            iGrid1.Rows[1].CellStyle.CustomDrawFlags = iGCustomDrawFlags.Foreground;          

            //add event handlers
            iGrid1.CustomDrawCellForeground +=
            new iGCustomDrawCellEventHandler(iGrid1_CustomDrawCellForeground);
        }

// Initialize Grid
private void InitializeGrid()
        {
            iGrid1.Rows.Count = 4;
            iGrid1.Cols.Count = 4;

            // Set values to rows and columns
            foreach (iGCell item in iGrid1.Cells)
            {
                if (item.Value == null)
                {
                    item.Value = "Row " + item.RowIndex.ToString() + ", Column " + item.ColIndex.ToString();
                }
            }

            // Set Column 2 backcolor as Yellow
            iGrid1.Cols[2].CellStyle.BackColor = Color.Yellow;
        }

// Draw red Border line
private void iGrid1_CustomDrawCellForeground(object sender, iGCustomDrawCellEventArgs e)
        {
            //draw rectangle
            e.Graphics.FillRectangle(
            Brushes.Red,
            e.Bounds.X,
            e.Bounds.Y + e.Bounds.Height - 2,
            e.Bounds.Width,
            4);
        }


// Set value on cell change
 private void iGridTasks_CurCellChanged(object sender, EventArgs e)
        {
            iGrid1.Cells[1, 2].Value = "abc";
        }

The values in Row 1 are not visible. If I double click in cell in row1 then that value is displayed.

How to handle it ?

(In my actual application on curCellChange I have code with many conditions to set cell values.)

Please let me know if any further details needed.

Thanks
-Mangesh
Igor/10Tec
2016-03-02T06:52:33Z
You redefine the cell foreground - that's why you do not see the cell values. You just need to put your drawing routine into the CustomDrawCellBackground event.

Pay attention to the fact that in the general case you should not draw outside of the cell bounds. In your sample, you draw the thick red line at the top of the 3rd row too.