提问人:Haakaash jaya soorya A S 提问时间:1/19/2022 更新时间:1/19/2022 访问量:177
如何在包含 4 个单选按钮的组框中将值设置为单个单选按钮,并在 c 中使用 grideview cellclick 事件#
How to set a value to single radio button in a group box containing 4 radio buttons with grideview cellclick event in c#
问:
如何从gridview中获取值并在组框中设置对应的单选按钮? dataGridView1.Rows[e.RowIndex]。Cells[2](如何将此值转换为字符 变量?这些值是网格视图中存在的“V”或“N”。
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.CurrentRow.Selected = true;
textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value+"";
textBox2.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value + "";
comboBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value + "";
}
答:
0赞
Caius Jard
1/19/2022
#1
假设表示 V 的单选按钮称为 vRadioButton 等,如下所示:
vRadioButton.Checked = "V".Equals(dataGridView1.CurrentRow.Cells[xxx].Value);
nRadioButton.Checked = "N".Equals(dataGridView1.CurrentRow.Cells[xxx].Value);
其中 是保存 V 或 N 的列的名称或编号xxx
最终,您必须将网格内值与常量进行比较,以生成设置为该布尔值的布尔值 abdChecked
评论
0赞
Haakaash jaya soorya A S
1/22/2022
vRadioButton.Checked = “V”。等于 (dataGridView1.CurrentRow.Cells[xxx]。值);数据类型是使用此代码实现的 CHAR,但结果没有变化
0赞
Haakaash jaya soorya A S
1/22/2022
将该单元格中的值存储到 char 变量的方法是什么?帮帮我兄弟
0赞
Caius Jard
1/22/2022
如果它是字符而不是字符串,请使用单引号而不是双引号'V'
'
"
评论