单击的那行数据添加到相应的文本框中
private void DbgStockPlan_CellClick(object sender, DataGridViewCellEventArgs e)(Click事件也试过效果一样)
{
int i = this.DbgStockPlan.CurrentCell.RowIndex;
(int i= this.DbgStockPlan.CurrentRow.Index; 也试过效果一样)
if (i >= 0)
{
this.TxtID.Text = this.DbgStockPlan[1, i].Value.ToString();
this.TxtCount.Text = this.DbgStockPlan[2, i].Value.ToString(); }
}
表里数据为
申请编号 材料编号 数量 用途 备注 材料名
P20082152243 W12 123 fdsa fsa 方便面 事件过后
this.TxtID.Text 的值为 fsa
this.TxtCount.Text 的值为 方便面 太奇怪了``
能找的地方都找过了``
不知道问题出在哪
private void DbgStockPlan_CellClick(object sender, DataGridViewCellEventArgs e)(Click事件也试过效果一样)
{
int i = this.DbgStockPlan.CurrentCell.RowIndex;
(int i= this.DbgStockPlan.CurrentRow.Index; 也试过效果一样)
if (i >= 0)
{
this.TxtID.Text = this.DbgStockPlan[1, i].Value.ToString();
this.TxtCount.Text = this.DbgStockPlan[2, i].Value.ToString(); }
}
表里数据为
申请编号 材料编号 数量 用途 备注 材料名
P20082152243 W12 123 fdsa fsa 方便面 事件过后
this.TxtID.Text 的值为 fsa
this.TxtCount.Text 的值为 方便面 太奇怪了``
能找的地方都找过了``
不知道问题出在哪
this.TxtCount.Text = this.DbgStockPlan[i, 2].Value.ToString(); 吧我记得GridView的索引是先Row再Column的...
楼主可以试一下,我记不太清了
int columnIndex,
int rowIndex
] { get; set; }
先列后行。
string columnName,
int rowIndex
] { get; set; }楼主可以试试:this.DbgStockPlan["材料编号", i]
this.DbgStockPlan["数量", i]
搞定
其实也不明白为什么
我这作业里用了N多DataGridView 但就这个出了乱子
嗯 多谢!