-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