if VeriTablosu
na satır ekle
DataRow row = datatable1.NewRow();
row["column2"]="column2";
row["column6"]="column6";
datatable1.Rows.Add(row);
Peki ya DataGridView
?
Yapabilirsin:
DataGridViewRow row = (DataGridViewRow)yourDataGridView.Rows[0].Clone();
row.Cells[0].Value = "XYZ";
row.Cells[1].Value = 50.2;
yourDataGridView.Rows.Add(row);
ya da:
DataGridViewRow row = (DataGridViewRow)yourDataGridView.Rows[0].Clone();
row.Cells["Column2"].Value = "XYZ";
row.Cells["Column6"].Value = 50.2;
yourDataGridView.Rows.Add(row);
Başka bir yol:
this.dataGridView1.Rows.Add("five", "six", "seven","eight");
this.dataGridView1.Rows.Insert(0, "one", "two", "three", "four");
Kimden: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rows.aspx
Bunun gibi:
dataGridView1.Columns[0].Name = "column2";
dataGridView1.Columns[1].Name = "column6";
string[] row1 = new string[] { "column2 value", "column6 value" };
dataGridView1.Rows.Add(row1);
Ya da .Rows()
özelliğini kullanarak değerleri ayrı ayrı ayarlamanız gerekir, bunun gibi:
dataGridView1.Rows[1].Cells[0].Value = "cell value";
Satır içermeyen bir DGV'ye Add() ile yeni bir satır eklemek, herhangi bir veri ekleyemeden (veya Tag özelliğine bir nesne bağlayamadan) önce SelectionChanged olayını yükseltir.
RowTemplate**'den bir klon satır oluşturmak daha güvenlidir:
//assuming that you created columns (via code or designer) in myDGV
DataGridViewRow row = (DataGridViewRow) myDGV.RowTemplate.Clone();
row.CreateCells(myDGV, "cell1", "cell2", "cell3");
myDGV.Rows.Add(row);