EQUINOXE
5 years ago
Hello good afternoon, I need to please help me to display the percentage code.

Thank you.

image.png

Click to View Image33 View(s)

Igor/10Tec
5 years ago
It can be found in the Folder Size Manager form in the main iGrid.NET demo. Here is the core code snippet:

Private Sub fGrid_CustomDrawCellForeground(ByVal sender As System.Object, ByVal e As TenTec.Windows.iGridLib.iGCustomDrawCellEventArgs) Handles fGrid.CustomDrawCellForeground
    ' Get the grid object from the sender parameter
    ' (this makes the drawing code easily reusable).
    Dim myGrid As iGrid = DirectCast(sender, iGrid)

    ' Check whether the cell has a value (draw nothing if not).
    Dim myObjValue As Object = myGrid.Cells(e.RowIndex, e.ColIndex).Value
    If myObjValue Is Nothing Then
        Return
    End If

    ' Add padding and space for the hot-tracking effect.
    Dim myBounds As Rectangle = e.Bounds
    myBounds.Inflate(-cPercentageBarPadding, -cPercentageBarPadding)
    ' Show level indent in this cell too.
    Dim myLevelWidth As Integer = myGrid.Rows(e.RowIndex).Level * myGrid.LevelIndent
    myBounds.X += myLevelWidth
    myBounds.Width -= myLevelWidth
    ' Deduct 1 pixel because GDI+ draws extra-1-pixel-width-and-height rectangles.
    myBounds.Width -= 1
    myBounds.Height -= 1

    If (myBounds.Width > 0) Then
        ' Fill the background.
        e.Graphics.FillRectangle(Brushes.Bisque, myBounds)

        ' Draw the visual representation of the percentage value.
        Dim myValue As Double = CDbl(myObjValue) ' value in percentages (double)
        Dim myWidth As Integer = CInt(myBounds.Width * myValue)
        e.Graphics.FillRectangle(Brushes.SandyBrown, myBounds.X, myBounds.Y, myWidth, myBounds.Height)

        ' Draw the percentage value as text.
        e.Graphics.DrawString(String.Format("{0:F2}%", myValue * 100), myGrid.Font, SystemBrushes.ControlText,
                                New RectangleF(myBounds.X, myBounds.Y, myBounds.Width + 1, myBounds.Height + 1), fPercentageBarStringFormat)

        ' Draw the border.
        e.Graphics.DrawRectangle(Pens.SaddleBrown, myBounds)

        ' Extra border for the hot-tracking effect.
        If e.RowIndex = fHotRowIndex Then
            myBounds.Inflate(1, 1)
            e.Graphics.DrawRectangle(Pens.SaddleBrown, myBounds)
        End If
    End If
End Sub
EQUINOXE
5 years ago
hi,
can be in c # code
Igor/10Tec
5 years ago
Here you are :)

private void fGrid_CustomDrawCellForeground(object sender, TenTec.Windows.iGridLib.iGCustomDrawCellEventArgs e)
{
  // Get the grid object from the sender parameter
  // (this makes the drawing code easily reusable).
  iGrid myGrid = sender as iGrid;

  // Check whether the cell has a value (draw nothing if not).
  object myObjValue = myGrid.Cells[e.RowIndex, e.ColIndex].Value;
  if (myObjValue == null)
    return;

  // Add padding and space for the hot-tracking effect.
  Rectangle myBounds = e.Bounds;
  myBounds.Inflate(-cPercentageBarPadding, -cPercentageBarPadding);
  // Show level indent in this cell too.
  int myLevelWidth = myGrid.Rows[e.RowIndex].Level * myGrid.LevelIndent;
  myBounds.X += myLevelWidth;
  myBounds.Width -= myLevelWidth;
  // Deduct 1 pixel because GDI+ draws extra-1-pixel-width-and-height rectangles.
  myBounds.Width -= 1;
  myBounds.Height -= 1;

  if (myBounds.Width > 0)
  {
    // Fill the background.
    e.Graphics.FillRectangle(Brushes.Bisque, myBounds);

    // Draw the visual representation of the percentage value.
    double myValue = (double)myObjValue; // value in percentages (double)
    int myWidth = (int)(myBounds.Width * myValue);
    e.Graphics.FillRectangle(Brushes.SandyBrown, myBounds.X, myBounds.Y, myWidth, myBounds.Height);

    // Draw the percentage value as text.
    e.Graphics.DrawString(string.Format("{0:F2}%", myValue * 100), myGrid.Font, SystemBrushes.ControlText,
      new RectangleF(myBounds.X, myBounds.Y, myBounds.Width + 1, myBounds.Height + 1), fPercentageBarStringFormat);

    // Draw the border.
    e.Graphics.DrawRectangle(Pens.SaddleBrown, myBounds);

    // Extra border for the hot-tracking effect.
    if (e.RowIndex == fHotRowIndex)
    {
      myBounds.Inflate(1, 1);
      e.Graphics.DrawRectangle(Pens.SaddleBrown, myBounds);
    }
  }
}

But I would recommend that you download and install the full iGrid.NET demo. It contains the full source code of all samples.
EQUINOXE
5 years ago

sorry, but the example (demo) is very complex, I am doing a basic example, please your help. thank you.

image.png

Click to View Image44 View(s)


image.png

Click to View Image44 View(s)

Igor/10Tec
5 years ago
You need to enable custom drawing of cell foreground in your cells. If you want to make it for a whole column, your code will look like this:

iGrid1.Cols[0].CellStyle.CustomDrawFlags = iGCustomDrawFlags.Foreground;

Then attach the event handler shown above to the CustomDrawCellForeground event.

You need almost all statements from the fGrid_CustomDrawCellForeground, you can only remove lines 12-18 because they are related to tree grids.
EQUINOXE
5 years ago
Thank you very much for the help, everything was perfect.