我使用了 DataGridview,它应该是手动填充的(未指定数据源)。我想获取第一行(索引-0)的内容。但它给了我空单元格值。
代码
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add("Description");
dt.Columns.Add("Unit Price");
dt.Columns.Add("Quantity");
dt.Columns.Add("Tot");
dr = dt.NewRow();
dr[0] = dataGridViewA_General.Rows[0].Cells[1].Value; //these values are null
dr[1] = dataGridViewA_General.Rows[0].Cells[2].Value; //these values are null
dr[2] = dataGridViewA_General.Rows[0].Cells[3].Value; //these values are null
dr[3] = dataGridViewA_General.Rows[0].Cells[4].Value; //these values are null
dt.Rows.Add(dr);
提前致谢
更新
// dataGridViewA_General
this.dataGridViewA_General.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridViewA_General.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Column_A_item_code,
this.Column_A_description,
this.Column_A_qntity,
this.Column_A_unit_price,
this.Column_A_list_total});
// Column_A_description
this.Column_A_description.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.Column_A_description.HeaderText = "Description";
this.Column_A_description.Name = "Column_A_description";
// Instantiate
private System.Windows.Forms.DataGridView dataGridViewA_General;
private System.Windows.Forms.DataGridViewTextBoxColumn Column_A_description;
(其余列也以相同方式定义。)