Im trying to get a value once I click on a checkbox for a custom DataGrid view filled with a SQL query. The idea its to build a list of selected items with the value ID_COMANDA to delete later
Now I dont know why Im getting a null exceptcion error. I tried to set it via data building it just dosent work
This is the funtion that sets data into the data grid
private void ComandasProcesadas(Mesas mesa_seleccionada)
{
// Fetch the data
List<Comanda> comandas_procesadas = Database.GetComandasActivas(mesa_seleccionada.ID_MESA);
// Set the AutoGenerateColumns property to false
COMANDAS_PROCESADAS.AutoGenerateColumns = false;
// Handle the CellPainting event to draw a larger checkbox
COMANDAS_PROCESADAS.CellPainting += new DataGridViewCellPaintingEventHandler(COMANDAS_PROCESADAS_CellPainting);
COMANDAS_PROCESADAS.CellContentClick += DataGridView_CellContentClick;
// Add the DataGridView to the form's controls
// this.Controls.Add(COMANDAS_PROCESADAS);
// Clear existing rows and set DataSource
COMANDAS_PROCESADAS.Rows.Clear();
COMANDAS_PROCESADAS.DataSource = comandas_procesadas;
}
This is the SQL query and data binding
while (reader.Read())
{
var comanda = new Comanda
{
ID_COMANDA = Convert.ToInt32(reader["ID_COMANDA"]),
NUM_COMANDA = Convert.ToInt32(reader["NUM_COMANDA"]),
CANTIDAD = Convert.ToDecimal(reader["CANTIDAD"]),
ITEM = reader["ITEM"].ToString(),
TOTAL = Convert.ToDecimal(reader["TOTAL"]),
NOTAS = reader["NOTAS"].ToString(),
NOMBRE_SALONERO = reader["NOMBRE_SALONERO"].ToString(),
FECHA = reader["FECHA"].ToString(),
TIEMPO_COMANDA = CalculateDifference(reader["FECHA"].ToString(), reader["HORA_INICIO"].ToString()),
IsNote = false // Regular row
};
Console.WriteLine(comanda.ToString());
comandas_procesadas.Add(comanda);
}
I dont know why Im failing. Any help is appreciated.
Thanks in advance !
Create a list of selected items