Hi Akram.19,
Create custom VerticalProgressBar class that inherits ProgressBar and rewrite the property CreateParams as follows.
Add a Panel to the Form in which you need to add the VerticalProgressBar to the form.
C#
public class VerticalProgressBar : ProgressBar
{
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Style |= 0x04;
return cp;
}
}
}
VB.Net
Public Class VerticalProgressBar
Inherits ProgressBar
Protected Overrides ReadOnly Property CreateParams As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.Style = cp.Style Or &H4
Return cp
End Get
End Property
End Class
Code
C#
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3]
{
new DataColumn("Id"),
new DataColumn("Name"),
new DataColumn("Value")
});
dt.Rows.Add(1, "Apple", "2");
dt.Rows.Add(2, "Banana", "6");
dt.Rows.Add(3, "Guava", "4");
dt.Rows.Add(4, "Orange", "9");
dataGridView1.AutoGenerateColumns = false;
dataGridView1.AllowUserToAddRows = false;
dataGridView1.ColumnCount = 2;
dataGridView1.Columns[0].HeaderText = "Name";
dataGridView1.Columns[0].Name = "Name";
dataGridView1.Columns[0].DataPropertyName = "Name";
dataGridView1.Columns[1].Name = "Value";
dataGridView1.Columns[1].HeaderText = "Value";
dataGridView1.Columns[1].DataPropertyName = "Value";
dataGridView1.DataSource = dt;
DataGridViewButtonColumn buttonColumn = new DataGridViewButtonColumn();
buttonColumn.HeaderText = "";
buttonColumn.Width = 60;
buttonColumn.Name = "buttonColumn";
buttonColumn.Text = "View";
buttonColumn.UseColumnTextForButtonValue = true;
dataGridView1.Columns.Insert(2, buttonColumn);
}
VerticalProgressBar bar = new VerticalProgressBar();
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 2)
{
DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
txtvalue.Text = row.Cells[1].Value.ToString();
int min = 1, max = 10;
bar.Value = (max / min) * int.Parse(txtvalue.Text);
bar.Height = 150;
panel1.Controls.Add(bar);
}
}
VB.Net
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(2) {
New DataColumn("Id"),
New DataColumn("Name"),
New DataColumn("Value")})
dt.Rows.Add(1, "Apple", "2")
dt.Rows.Add(2, "Banana", "6")
dt.Rows.Add(3, "Guava", "4")
dt.Rows.Add(4, "Orange", "9")
dataGridView1.AutoGenerateColumns = False
dataGridView1.AllowUserToAddRows = False
dataGridView1.ColumnCount = 2
dataGridView1.Columns(0).HeaderText = "Name"
dataGridView1.Columns(0).Name = "Name"
dataGridView1.Columns(0).DataPropertyName = "Name"
dataGridView1.Columns(1).Name = "Value"
dataGridView1.Columns(1).HeaderText = "Value"
dataGridView1.Columns(1).DataPropertyName = "Value"
dataGridView1.DataSource = dt
Dim buttonColumn As DataGridViewButtonColumn = New DataGridViewButtonColumn()
buttonColumn.HeaderText = ""
buttonColumn.Width = 60
buttonColumn.Name = "buttonColumn"
buttonColumn.Text = "View"
buttonColumn.UseColumnTextForButtonValue = True
dataGridView1.Columns.Insert(2, buttonColumn)
End Sub
Private bar As VerticalProgressBar = New VerticalProgressBar()
Private Sub dataGridView1_CellContentClick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles dataGridView1.CellContentClick
If e.ColumnIndex = 2 Then
Dim row As DataGridViewRow = dataGridView1.Rows(e.RowIndex)
txtvalue.Text = row.Cells(1).Value.ToString()
Dim min As Integer = 1, max As Integer = 10
bar.Value = (max / min) * Integer.Parse(txtvalue.Text)
bar.Height = 150
panel1.Controls.Add(bar)
End If
End Sub
Screenshot