所以我有我的 Winform,其中有一个包含数据的 dgv,当单击相应的单元格时,我需要能够将该数据保存到两个单独的数组列表中。真的没问题,但我有可能是有史以来最愚蠢的错误:我需要实例化数组列表所在的类,“clsAL”,但程序仍然抛出错误,认为“对象引用未设置为对象的实例”。这是代码(忽略与此无关的任何内容,特别是如果它是西班牙语:D)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication7
{
public partial class FormH : Form
{
clsAL cls;
public FormH()
{
InitializeComponent();
}
private void FormH_Load(object sender, EventArgs e)
{
cls = new clsAL();
OleDbCommand comm;
OleDbConnection conn = new OleDbConnection();
DataSet dset;
OleDbDataAdapter adap = new OleDbDataAdapter();
OleDbCommandBuilder cmb;
conn.ConnectionString = "Provider = 'Microsoft.Jet.OLEDB.4.0'; Data Source = 'RoboTIC.mdb'";
comm = new OleDbCommand("Select * From tblHistorial", conn);
adap = new OleDbDataAdapter(comm);
dset = new DataSet();
adap.Fill(dset, "tblHistorial");
dgvHistorial.DataSource = dset.Tables["tblHistorial"];
}
private void dgvHistorial_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
cls = new clsAL();
string operacion = dgvHistorial.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
cls.dir.Clear();
cls.time.Clear();
string aux = "";
for (int a = 0; a > operacion.Length; a++)
{
aux = aux + operacion[a];
if (aux == "a")
{
cls.dir.Add("avanzar");
}
if (aux == "d")
{
cls.dir.Add("derecha");
}
if (aux == "i")
{
cls.dir.Add("izquierda");
}
if (aux == "r")
{
cls.dir.Add("retroceder");
}
if (aux == "/")
{
}
if (aux != "a" && aux != "a" && aux != "a" && aux != "a" && aux != "/")
{
cls.time.Add(Convert.ToInt32(operacion[a]+operacion[a+1]));
}
}
}
}
}