I would like to request your support to select some items from my datagridview when selecting an option in the checkedlistbox. Example if I select option 2 only the last 3 options must be marked on the grid. I only achieve that everything is selected but I want to establish by row index which is what is selected in the grid. This is my form:
I am using language c # in visual studio 2015 and sql server 2016 .. This is my code of the form:
namespace CapaPresentacion
{
public partial class FrmCombos : Form
{
public FrmCombos()
{
InitializeComponent();
}
double Precio = 0;
private void dataServicio_CellContentClick(object sender,
DataGridViewCellEventArgs e)
{
if (dataServicio.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "1")
{
dataServicio.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = "0";
}
else
{
dataServicio.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = "1";
}
}
//metodo ocultar columnas
private void OcultarColumnas()
{
this.dataServicio.Columns[4].Visible = false;
}
private void dataServicio_CellValueChanged(object sender,
DataGridViewCellEventArgs e)
{
if (dataServicio.Columns[e.ColumnIndex].Name == "Seleccionarse")
{
DataGridViewRow row = dataServicio.Rows[e.RowIndex];
DataGridViewCheckBoxCell cellSeleccion = row.Cells["Seleccionarse"] as DataGridViewCheckBoxCell;
}
}
private void dataServicio_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (dataServicio.IsCurrentCellDirty)
{
dataServicio.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}
private void FrmCombos_Load(object sender, EventArgs e)
{
// TODO: esta línea de código carga datos en la tabla 'dsPrincipal.spcombo_venta' Puede moverla o quitarla según sea necesario.
this.spcombo_ventaTableAdapter.Fill(this.dsPrincipal.spcombo_venta);
this.OcultarColumnas();
}
private void chkKits_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataServicio.Rows)
{
row.Cells[Seleccionarse.Name].Value = true;
Precio += Convert.ToDouble(row.Cells[3].Value);
}
txtTotal.Text = Convert.ToString(Precio);
txtTotal.Text = (double.Parse(txtTotal.Text)).ToString("#,#.00");
}
}
}
Thanks in advance !!!