how to add column dynamical开发者_JAVA百科ly in datagridview using c#
For example:
DataGridViewColumn col = new DataGridViewTextBoxColumn();
col.HeaderText = "Hi there";
int colIndex = grid.Columns.Add(col);
If it's like any of the other .Net grid controls:
YourDataGridView.Columns.Add(New DataGridViewColumn());
I you mean to add all value on particular column then maybe it could help you.
Try this tips:
for (int i=0; i< datagriview1.coulums.count -1; i++)
{
int total + = total + datagridview1.columns[i]
.cell[index for columns you want to add].formatedvalue.toString();
}
textbox1.text=total;
Try that code. it can help you.
Thanks, Nico
I am also tested this code you mean to add all value on particular column then maybe it could help you. Try this tips:
gridView1.Columns.Clear();
gridView1.Columns.Add(new GridColumn() {Caption = @"Caption", FieldName = "FieldName", Name = "FieldName", Visible = true});
精彩评论