Note that there are some explanatory texts on larger screens.

plurals
  1. POobjects in datagridview
    primarykey
    data
    text
    <p>Im adding objects to a datagridview ( only one kind) through a list ej. <code></p> <pre><code>List&lt;Material&gt; mater = new List&lt;Material&gt;(); DataGridView dgvMAterial = new DataGridView(); dgvMaterial.DataSource = null; mater.Add((Material)cmbMaterial.SelectedValue); dgvMaterial.DataSource = mater; </code></pre> <p></code> But every time I click over the datagrid I get an indexoutofrangeexeption. Can somone tell me why? thanks</p> <p>here is my whole code for the form</p> <pre><code>public partial class inicio : Form { private string ConnectionString = "Data Source=localhost\\sqlexpress;Initial Catalog=data.mdf;Integrated Security=SSPI;"; //private string ConnectionString = "Server=.\\SQLExpress;AttachDbFilename=|DataDirectory|\\data\\data_data.mdf.mdf; Database=data.mdf;Trusted_Connection=Yes;"; private ISessionFactory sessionFactory; List&lt;Material&gt; mater = new List&lt;Material&gt;(); List&lt;Salarios&gt; salar = new List&lt;Salarios&gt;(); IBindingList mind = new BindingList&lt;Salarios&gt;(); Productos prod; public inicio() { InitializeComponent(); sessionFactory = nhn.BusinessObjects.Initialize.CreateSessionFactory(ConnectionString); dgvMaterial.DataSource = mater; } private void materialToolStripMenuItem_Click(object sender, EventArgs e) { Catalogos.frmMaterial material = new costeos.Catalogos.frmMaterial(ConnectionString); material.ShowDialog(this); material.Dispose(); } private void salariosToolStripMenuItem_Click(object sender, EventArgs e) { Catalogos.frmSalarios salarios = new costeos.Catalogos.frmSalarios(ConnectionString); salarios.ShowDialog(this); salarios.Dispose(); } private void agregarToolStripMenuItem_Click(object sender, EventArgs e) { Catalogos.frmAddRemuneraciones rem = new costeos.Catalogos.frmAddRemuneraciones(ConnectionString); rem.ShowDialog(this); rem.Dispose(); } private void agregarToolStripMenuItem1_Click(object sender, EventArgs e) { Catalogos.frmAddAdmin adm = new costeos.Catalogos.frmAddAdmin(ConnectionString); adm.ShowDialog(this); adm.Dispose(); } private void agregarToolStripMenuItem2_Click(object sender, EventArgs e) { Catalogos.frmAddInsumosInd insumos = new costeos.Catalogos.frmAddInsumosInd(ConnectionString); insumos.ShowDialog(this); insumos.Dispose(); } private void txt_KeyPress(object sender, KeyPressEventArgs e) { if (char.IsDigit(e.KeyChar) || char.IsPunctuation(e.KeyChar) || char.IsControl(e.KeyChar)) { e.Handled = false; } else { e.Handled = true; } } private void inicio_Load(object sender, EventArgs e) { LlenaCampos(); } private void LlenaCampos() { using (var session = sessionFactory.OpenSession()) { using (var transaction = session.BeginTransaction()) { var mat = session.CreateCriteria(typeof(Material)) .List&lt;Material&gt;(); var sal = session.CreateCriteria(typeof(Salarios)) .List&lt;Salarios&gt;(); transaction.Commit(); cmbMaterial.DataSource = mat; cmbMaterial.DisplayMember = "Nombre"; cmbSalarios.DataSource = sal; cmbSalarios.DisplayMember = "Nombre"; cmbMIndirecta.DataSource = sal; cmbMIndirecta.DisplayMember = "Nombre"; } } } private void btnAddMaterial_Click(object sender, EventArgs e) { materialBindingSource.DataSource = null; //dgvMaterial.DataSource = null; mater.Add((Material)cmbMaterial.SelectedValue); //dgvMaterial.DataSource = mater; dgvMaterial.DataSource = materialBindingSource; materialBindingSource.DataSource = mater; materialBindingSource.ResetBindings(false); } private void button2_Click(object sender, EventArgs e) { dgvSalarios.DataSource = null; salar.Add((Salarios)cmbSalarios.SelectedValue); dgvSalarios.DataSource = salar; } private void button3_Click(object sender, EventArgs e) { dgvMIndirecta.DataSource = null; mind.Add((Salarios)cmbMIndirecta.SelectedValue); dgvMIndirecta.DataSource = mind; } private void button1_Click(object sender, EventArgs e) { using (var session = sessionFactory.OpenSession()) { using (var transaction = session.BeginTransaction()) { if (prod == null) { prod = new Productos { CargasTurno = float.Parse(txtCargasTurno.Text), CavidadesMolde = int.Parse(txtCavidadesMolde.Text), Clave = txtClave.Text, Comentarios = txtComentarios.Text, MezclasTurno = float.Parse(txtMezclasTurno.Text), Moldes = int.Parse(txtMoldes.Text), Nombre = txtNombre.Text, Peso = float.Parse(txtPesoTotal.Text), TotalPza = int.Parse(txtPzasTotales.Text), Turnos = int.Parse(txtTurnos.Text) }; session.Save(prod); transaction.Commit(); } foreach (DataGridViewRow dr in dgvMaterial.Rows) { Material m = dr.DataBoundItem as Material; m.Materiales PMaterial mat = new PMaterial { Material = dr.DataBoundItem as Material, Cantidad = float.Parse(dr.Cells["Cantidad"].Value.ToString()), Fecha = DateTime.Now, Producto = prod }; session.Save(mat); } transaction.Commit(); session.Close(); } } } } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload