I want to put a progress bar on a column. The in-built columns seem to support only text (with a checkbox and an icon) and combobox. I need more. How can I draw on a column myself?
I want to achieve something like this.
Or this.
Last edit: YourGod 2017-02-07
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
After investigating the source code, I created a custom Control like the following and achieved what I wanted. I am adding this to help people in the future having the same requirements as I did.
The treeColume2 was bound to Progress property which had a value ranging from 0 to 100.
I want to put a progress bar on a column. The in-built columns seem to support only text (with a checkbox and an icon) and combobox. I need more. How can I draw on a column myself?
I want to achieve something like this.
![](https://www.planet-source-code.com/Upload_PSC/ScreenShots/PIC200410102115443894.gif)
Or this.
![](http://10tec.com/articles/screenshots/treeview-in-datagridview-example.png)
Last edit: YourGod 2017-02-07
After investigating the source code, I created a custom Control like the following and achieved what I wanted. I am adding this to help people in the future having the same requirements as I did.
The
treeColume2
was bound toProgress
property which had a value ranging from 0 to 100.ProgressNode progNode = new ProgressNode();
progNode.ParentColumn = treeColumn2;
progNode.DataPropertyName = "Progress";
treeViewAdv1.NodeControls.Add(progNode);
class ProgressNode : BindableControl
{
static Size TestSize = new Size(200, 16);
static SolidBrush BarBrush = new SolidBrush(Color.LightBlue);
static SolidBrush LabelBrush = new SolidBrush(Color.Black);
StringFormat CenterFormat =
new StringFormat
{
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center
};
public override void Draw(TreeNodeAdv node, DrawContext context)
{
var g = context.Graphics;
var percentage = (int)GetValue(node);
var fillRect = context.Bounds;
int newWidth = fillRect.Width * percentage / 100;
fillRect.Width = newWidth;
g.FillRectangle(BarBrush, fillRect);
g.DrawString($"{percentage}%", context.Font, LabelBrush, context.Bounds, CenterFormat);
}
public override Size MeasureSize(TreeNodeAdv node, DrawContext context)
{
return TestSize;
}
}
Last edit: YourGod 2017-02-07