我需要的功能是单击某个单元格的时候,另一个dataGrid显示出与这个单元格内容相关的dataTable。
我想到的办法是给textbox的Enter事件,可是不管用,一直不能触发。
我的代码:
DataGridTableStyle style = new DataGridTableStyle();
style.MappingName = "Table_Material";
DataGridTextBoxColumn m_name = new DataGridTextBoxColumn();
m_name.HeaderText = "原料名称";
m_name.MappingName = "Material_Name";
m_name.ReadOnly = false;
m_name.Width = 360;
m_name.TextBox.Enter += new System.EventHandler(TextBoxEnterHandler);//这里的事件去执行想做的事情
// 但是它就是不触发
style.GridColumnStyles.AddRange(new DataGridColumnStyle[] { m_id, m_name, m_gcas, comboFlag1 });
dataGrid1.TableStyles.Clear();
dataGrid1.TableStyles.Add(style);
我想到的办法是给textbox的Enter事件,可是不管用,一直不能触发。
我的代码:
DataGridTableStyle style = new DataGridTableStyle();
style.MappingName = "Table_Material";
DataGridTextBoxColumn m_name = new DataGridTextBoxColumn();
m_name.HeaderText = "原料名称";
m_name.MappingName = "Material_Name";
m_name.ReadOnly = false;
m_name.Width = 360;
m_name.TextBox.Enter += new System.EventHandler(TextBoxEnterHandler);//这里的事件去执行想做的事情
// 但是它就是不触发
style.GridColumnStyles.AddRange(new DataGridColumnStyle[] { m_id, m_name, m_gcas, comboFlag1 });
dataGrid1.TableStyles.Clear();
dataGrid1.TableStyles.Add(style);
你应该是要TextBox_Enter一上DataGrid显视跟TextBox相关的信息吧
现在的问题是,根本就不触发这个事件。
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
for (int i = 0; i < this.dataGridView1.RowCount; i++)
for (int j = 0; j < 2; j++)
{
if (this.dataGridView1.Rows[i].Cells[j].Selected == true)
{
//this.textBox_content.Text = this.dataGridView1.Rows[i].Cells[j].Value.ToString();
//根据选择的内容绑定另外一个dataGridView的数据
}
}
}
应该差不多吧
我改成m_name.TextBox.Click += new EventHandler(TextBoxEnterHandler);
依然不会触发。
把TextBox.Enter改成单元格点击事件或者是 TextBox.onCurse(记不清了,就是获得焦点事件)
这个试一下
比DataGrid高级多了
comlihongbin老兄,datagrid没有onfocus事件。
那么怎么给datagridview的一列指定单元格单击事件呢?