I'm using a datagridview on 4.5 version of .NET with Visual Studio Express 2012. My code is currently the following:
this.dgv_proveedores.AllowUserToAddRows = false;
this.dgv_proveedores.AllowUserToDeleteRows = false;
this.dgv_proveedores.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgv_proveedores.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.id,
this.razon_social,
this.rubro,
this.cuit,
this.seleccionar});
this.dgv_proveedores.Location = new System.Drawing.Point(34, 202);
this.dgv_proveedores.Margin = new System.Windows.Forms.Padding(2);
this.dgv_proveedores.Name = "dgv_proveedores";
this.dgv_proveedores.ReadOnly = true;
this.dgv_proveedores.RowTemplate.Height = 24;
this.dgv_proveedores.Size = new System.Drawing.Size(486, 154);
this.dgv_proveedores.TabIndex = 13;
this.dgv_proveedores.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgv_proveedores_CellContentClick);
private void dgv_proveedores_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex < 0)
{
return;
}
if (e.ColumnIndex == dgv_proveedores.Columns["seleccionar"].Index)
{
int id = int.Parse(dgv_proveedores.Rows[e.RowIndex].Cells[0].Value.ToString());
//TODO llamar a DAO proveedor para conseguir el proveedor con el ID
}
}
With the event as coded above, I only get the "Seleccionar" Cell, and with Cells[1] I get null.
I don't want to select the row before clicking the button, if possible.