本人菜虫有一表"Table",表中含有"otherID"列(otherID为外键),现建有DataGridView绑定于"Table"表,想实现点击GridView中的某一行时,能在ComboBox的Text中显示"otherID"的值,请高手给出可行的代码并能尽量仔细解释一下! private void dGV_CellClicked(object sender, DataGridViewCellEventArgs e)
{
//请高手在此给出代码,谢啦~!
}-------------------------------
另想实现比较复杂点的功能:就是如何在ComboBox中显示的是与之相关联的外表"otherTable"中"otherID"对应的"otherName"的值而不是直接显示"otherID"值,也一并请教一下!再次感谢~!!
是不是我表达能力不强,词不达意,没人弄懂我的意思啊?~~~~(>_<)~~~~ 555...
因为刚开始自学C#,所以就边做边看学习资料(光对着书本我会犯困的,而且理解也不深刻+_+!)..
快来人解答下,我卡在这里啦...o(>﹏<)o
让ComboBox显示所选行的信息...清晰点了没(⊙o⊙)?
comboBox1.Items.Add("+你那一行对应的otherName+");
不行吗?
comboBox.Items .Add= dgv.Rows[dgv.CurrentRow.Index].Cells["otherID"].Value.ToString();
7楼已经给出答案了
private void dGV_CellClicked(object sender, DataGridViewCellEventArgs e)
{
int rows = dataGridView1.indexrows;//获得选种行的索引
string str = dataGridView1.rows[rows].cells[num].text;//获取第rows行的索引为num列的值
comboBox1.Items.Add(str);
}
不知道对不对,因为没用过dataGridView
学习ing...O(∩_∩)O~
comboBox.Items .Add= dgv.Rows[dgv.CurrentRow.Index].Cells["otherID"].Value.ToString();
上面代码中dgv.Rows[dgv.CurrentRow.Index]的意思有些不理解,是dgv所有行中当前行的位置..?! (⊙_⊙?)
int r=dataGridView1.CurrentRow.Index;
comboBox1.Text = dataGridView1.Rows[r].Cells["otherID"].Value.ToString();
注:"otherID"在"Table"表中为外键,是属于"Table2"中的主键;"otherName"是存在表"Table2"中的.
PS:问题有点多,我会加分的..现在不让加分,要到明天才能加...拜托了o(≧v≦)o~~