-1
,所以我有我的WinForm的,其中我有它的数据DGV,我需要能够将这些数据保存到两个独立的ArrayList点击此时,相应的单元格时。 没有这一问题真的,但我甲肝这可能是可能是有史以来编程的最愚蠢的错误: 我需要实例,其中的ArrayList是,“clsAL”之类,但该程序仍引发一个错误,认为“你调用的对象是空的”。下面的代码(则会忽略任何无关这一点,特别是如果它在西班牙语:d)C#实例错误
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]));
}
}
}
}
}
问题可能出在'clsAl'类。在您尝试对其进行操作时,您可能没有分配该班级的其中一个ArrayList。你能发布完整的异常信息(堆栈跟踪)吗? – evanmcdonnal
我怀疑,因为我与此的ArrayList以其他形式在同一proyect工作,我没有问题, – user1800870
好吧,桩100行代码,而不是堆栈跟踪你的基本的错误。祝你好运获得帮助。 – evanmcdonnal