选择数据网格视图行值并将其传递给另一个窗体
本文关键字:窗体 另一个 数据网 数据 网格 视图 选择 | 更新日期: 2023-09-27 18:30:37
在我的应用程序中,我想在我的datagridview
中选择一整行并将其传递给位于另一种形式的组合框。我用以下代码尝试了它,但它给我抛出了错误"方法'this'没有重载需要 1 个参数"
这是我的代码
if(dataGridView1.SelectedCells.Count > 0)
{
var oneCell = dataGridView1[0];
int editloannumber = int.Parse(dataGridView1.Rows[oneCell.RowIndex].Cells[0].Value.ToString());
int editlid = int.Parse(dataGridView1.Rows[oneCell.RowIndex].Cells[8].Value.ToString());
string editloantype = dataGridView1.Rows[oneCell.RowIndex].Cells[1].Value.ToString();
string editneworsecond = dataGridView1.Rows[oneCell.RowIndex].Cells[2].Value.ToString();
string editpurpose = dataGridView1.Rows[oneCell.RowIndex].Cells[11].Value.ToString();
string editstatus = dataGridView1.Rows[oneCell.RowIndex].Cells[3].Value.ToString();
string editcomments = dataGridView1.Rows[oneCell.RowIndex].Cells[7].Value.ToString();
string editretail = dataGridView1.Rows[oneCell.RowIndex].Cells[12].Value.ToString();
wartif_UW.editform e2 = new wartif_UW.editform(editloannumber, editloantype, editneworsecond, editpurpose, editstatus, editcomments, editretail,editlid);
e2.ShowDialog();
}
这是我的第二个表单构造器
public editform(int editln, string edittype, string editno2, string purpo, string stat, string come,string reti,int lid)
{
InitializeComponent();
comboload();
loannumbertxtbox.Text = editln ;
loantypecombobox.Text = edittype;
loanpurposrcombo.Text = purpo;
neworseccombobox.Text = editno2;
retailregcombo.Text = reti;
statuscombbox.Text = stat;
commnetrichtext.Text = come;
}
DataGridView 没有索引器。你必须做这样的事情:
if (dataGridView1.SelectedCells.Count > 0)
{
var oneCell = dataGridView1.SelectedCells[0];
int editloannumber = int.Parse(dataGridView1.Rows[oneCell.RowIndex].Cells[0].Value.ToString());
int editlid = int.Parse(dataGridView1.Rows[oneCell.RowIndex].Cells[8].Value.ToString());
string editloantype = dataGridView1.Rows[oneCell.RowIndex].Cells[1].Value.ToString();
string editneworsecond = dataGridView1.Rows[oneCell.RowIndex].Cells[2].Value.ToString();
string editpurpose = dataGridView1.Rows[oneCell.RowIndex].Cells[11].Value.ToString();
string editstatus = dataGridView1.Rows[oneCell.RowIndex].Cells[3].Value.ToString();
string editcomments = dataGridView1.Rows[oneCell.RowIndex].Cells[7].Value.ToString();
string editretail = dataGridView1.Rows[oneCell.RowIndex].Cells[12].Value.ToString();
wartif_UW.editform e2 = new wartif_UW.editform(editloannumber, editloantype, editneworsecond, editpurpose, editstatus, editcomments, editretail, editlid);
e2.ShowDialog();
}