在c#中从foreach到for for for for dataGridView combobox列
以下是我的代码,
dataGridView1.DataSource = dt;
dataGridView1.AllowUserToAddRows = false;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataGridViewComboBoxCell comboBoxCell = (row.Cells[1] as DataGridViewComboBoxCell);
foreach (DataRow drow in dt.Rows)
{
string customerId = drow[0].ToString();
comboBoxCell.Items.Add(drow[1]);
if (row.Cells[0].Value.ToString() == customerId)
{
comboBoxCell.Value = drow[1];
}
}
}
我想更改foreach循环以进行循环
,
(dataGridView1.Columns[1] as DataGridViewComboBoxColumn).DataSource = dt;
for (int i = 0; i <dataGridView1.Rows.Count; i++)
{
dataGridView1.Rows[i].Cells[1].Value = dt;
}
但并未显示我所需的结果 请提出任何建议 问候
The below is my code
dataGridView1.DataSource = dt;
dataGridView1.AllowUserToAddRows = false;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataGridViewComboBoxCell comboBoxCell = (row.Cells[1] as DataGridViewComboBoxCell);
foreach (DataRow drow in dt.Rows)
{
string customerId = drow[0].ToString();
comboBoxCell.Items.Add(drow[1]);
if (row.Cells[0].Value.ToString() == customerId)
{
comboBoxCell.Value = drow[1];
}
}
}
i want to change the foreach loop into for loop
like
(dataGridView1.Columns[1] as DataGridViewComboBoxColumn).DataSource = dt;
for (int i = 0; i <dataGridView1.Rows.Count; i++)
{
dataGridView1.Rows[i].Cells[1].Value = dt;
}
but it is not showing my required result
Please any suggestion
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论