C# 选择datagridview行值并将其传递给另一个窗体
在我的应用程序中,我想在datagridview中选择一整行,并将其传递给位于另一个表单中的组合框。我用下面的代码进行了尝试,但它向我抛出了错误“this”方法不重载1个参数 这是我的密码C# 选择datagridview行值并将其传递给另一个窗体,c#,datagridview,C#,Datagridview,在我的应用程序中,我想在datagridview中选择一整行,并将其传递给位于另一个表单中的组合框。我用下面的代码进行了尝试,但它向我抛出了错误“this”方法不重载1个参数 这是我的密码 if(dataGridView1.SelectedCells.Count > 0) { var oneCell = dataGridView1[0]; int editloannumber = int.Parse(dataGridView1.Rows[oneCell.RowIndex].
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();
}
你能发布editform的代码吗?当然我更新了我的问题:对不起,有人在我更新时编辑了它。我再次更新了我的问题哪一行抛出了错误。。?组合载荷;您的错误如果是此错误,则希望您使用至少一个参数调用它,您能否显示comboload的外观..?行中的错误:var oneCell=dataGridView1[0];DataGridView不是集合/索引类型。试试这个:var oneCell=datagridview.CurrentCell;谢谢你的回答,先生