2012-10-20 64 views

回答

1

您可以通過使用

GridView1.DataSource = DataTable中添加它;

,然後通過此

datatable.Rows.Add添加新行();

這將添加新行並將控件ID添加到add()中。

+0

我可以把按鈕的DataGridView的最後一排握的最後一排握??? – Aditya

+0

是的,你可以把它。 – Hitesh

+0

.......... ??? – Aditya

1
use this 

public partial class Form1 : Form 
    { 
     Button textBoxDgv1 = new Button(); 
     Label labelDgv1 = new Label(); 
the next is on the Form_Load event 

private void Form1_Load(object sender, EventArgs e) 
     { 
      labelDgv1.Text = "Delete"; 
      labelDgv1.Height = 20; 
      labelDgv1.AutoSize = false; 
      labelDgv1.BorderStyle = BorderStyle.FixedSingle; 
      labelDgv1.TextAlign = ContentAlignment.MiddleCenter; 
      int Xdgv1 = this.dataGridView1.GetCellDisplayRectangle(2, -1, true).Location.X; 
      labelDgv1.Width = this.dataGridView1.Columns[2].Width + Xdgv1; 
      labelDgv1.Location = new Point(0, this.dataGridView1.Height - textBoxDgv1.Height); 
      this.dataGridView1.Controls.Add(labelDgv1); 

and one more section is in dataGridView1_CellPainting 

private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) 
{ 
     int sum = 0; 
     for (int i = 0; i < this.dataGridView1.Rows.Count; i++) 
     { 
      if (dataGridView1.Rows[i].Cells[3].Value != string.Empty) 
      { 
       sum += Convert.ToInt32(this.dataGridView1[3, i].Value); 
      } 
     } 
      textBoxDgv1.Text = sum.ToString(); 
      int Xdgvx = this.dataGridView1.GetCellDisplayRectangle(2, -1, true).Location.X; 
      labelDgv1.Width = this.dataGridView1.Columns[2].Width + Xdgvx; 
      labelDgv1.Location = new Point(0, this.dataGridView1.Height - textBoxDgv1.Height); 
      textBoxDgv1.Width = this.dataGridView1.Columns[3].Width; 
      Xdgvx = this.dataGridView1.GetCellDisplayRectangle(3, -1, true).Location.X; 
      textBoxDgv1.Location = new Point(Xdgvx, this.dataGridView1.Height - textBoxDgv1.Height); 
} 
+0

Thnx .............. :) – Aditya

+0

如果您對此感到滿意,請選擇此答案。 – Hitesh

相關問題