Hi Akram.19,
Check the below example.
I have added a DatGridView, a TextBox and a ProgressBar control in the Form.
Inside the DatGridView i have added a Button column. When the Button is clicked, based on the value the progress percentage is calculated and the value is set to display the ProgressBar using Value property inside the DataGridView CellContentClick event.
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);
}
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;
progressBar1.Value = (max / min) * int.Parse(txtvalue.Text);
}
}
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 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
progressBar1.Value = (max / min) * Integer.Parse(txtvalue.Text)
End If
End Sub
Screenshot