【发布时间】:2014-09-12 16:57:10
【问题描述】:
所以我有一个看起来像这样的表单:
我在加载函数中为dataviewgrid生成数据表:
private void loadEmpresas(){
MySqlConnection myConn = new MySqlConnection(gVariables.myConnection);
MySqlCommand command = new MySqlCommand("Select codempresa as 'Codigo', nomempresa as 'Nombre empresa' from contabilidad.empresas", myConn);
try
{
MySqlDataAdapter sda = new MySqlDataAdapter();
sda.SelectCommand = command;
DataTable dbdataset = new DataTable();
sda.Fill(dbdataset);
BindingSource bSource = new BindingSource();
bSource.DataSource = dbdataset;
dataGridView1.DataSource = bSource;
sda.Update(dbdataset);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
mysql中的表是这样的:
所以当它运行时会显示:
现在我遇到的问题是我不知道如何修改列的宽度,像整个表格一样覆盖灰色空间,我希望它在单击时选择整行而不仅仅是一个单元格。当它单击行时,我想填充其余的文本框,但是单击事件有问题,出于测试目的是这样的:
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
MessageBox.Show("clicked");
if (e.RowIndex >= 0)
{
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
MessageBox.Show(row.Cells[0].Value.ToString() + row.Cells[1].Value.ToString());
}
else
{
MessageBox.Show("wat");
}
}
当我点击它时,有时甚至不显示消息框,我真的不知道如何正确处理点击行事件:C 请帮助 T_T
【问题讨论】:
标签: c# mysql datagridview datatable