如何仅编辑datagridview中的选定行 [英] how to edit only selected row in datagridview
本文介绍了如何仅编辑datagridview中的选定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
先生;
i只想编辑datagridview中的选定行。
但是
在我的情况下只编辑第一行我希望每当
i选择任何行并点击编辑按钮然后特别
行数据显示在文本框中。
以下是我的代码:
Bind();
int i;
i = dataGridView1.SelectedCells [ 0 ]。RowIndex;
txtto.Text = dataGridView1.Rows [i] .Cells [ 5 ]。Value.ToString();
txtsubject.Text = dataGridView1.Rows [i] .Cells [ 1 ]。Value.ToString();
txtfrom.Text = dataGridView1.Rows [i] .Cells [ 8 ]。Value.ToString();
txtdisp.Text = dataGridView1.Rows [i] .Cells [ 3 ]。Value.ToString();
txtdepthide.Text = dataGridView1.Rows [i] .Cells [ 6 ]。Value.ToString();
dateTimePicker1.Value = Convert.ToDateTime(dataGridView1.Rows [i] .Cells [ 7 ]。Value.ToString());
txtrefer.Text = dataGridView1.Rows [i] .Cells [ 4 ]。Value.ToString();
请帮助我,你的回答对我很有帮助。
提前谢谢!
解决方案
< blockquote>尝试使用CurrentRow而不是SelectedCells。
i = dataGridView1.CurrentRow.Index;
或直接使用它......
txtto.Text = dataGridView1。 CurrentRow.Cells [5] .Value.ToString();
hi sir;
i want to edit only selected rows in datagridview.
but
in my case only first row is edited i want that whenever
i select any row and click on edit button then particular
row data is displayed in textbox.
below is my code:
Bind();
int i;
i = dataGridView1.SelectedCells[0].RowIndex;
txtto.Text = dataGridView1.Rows[i].Cells[5].Value.ToString();
txtsubject.Text = dataGridView1.Rows[i].Cells[1].Value.ToString();
txtfrom.Text = dataGridView1.Rows[i].Cells[8].Value.ToString();
txtdisp.Text = dataGridView1.Rows[i].Cells[3].Value.ToString();
txtdepthide.Text = dataGridView1.Rows[i].Cells[6].Value.ToString();
dateTimePicker1.Value =Convert.ToDateTime(dataGridView1.Rows[i].Cells[7].Value.ToString());
txtrefer.Text = dataGridView1.Rows[i].Cells[4].Value.ToString();
please help me your answer really helpful for me.
thanks in advance!
解决方案
Try using CurrentRow instead of SelectedCells.
i = dataGridView1.CurrentRow.Index;
Or directly use it...
txtto.Text = dataGridView1.CurrentRow.Cells[5].Value.ToString();
这篇关于如何仅编辑datagridview中的选定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文