I can't seem to figure out why a datagridview is not populating. (Also, a
weird error came up when tracing)
I'm attempting to pull data from a SQLite database, and the first DGV
loads just fine, but the second doesn't. When debugging, I get this:
-Current 'this.specListing.Current' threw an exception of type
'System.IndexOutOfRangeException' object {System.IndexOutOfRangeException}
this.specListing is a BindingSource. The more specific error is "Index -1
does not have a value", and there are 2 items (Count: 2)
The code is:
public frmClassEditor()
{
//start listing
InitializeComponent();
this.clsList = new List<SQLiteDataPair>();
this.specList = new List<pilotSpec>();
//create binding sources
this.clsListing = new BindingSource();
this.specListing = new BindingSource();
//updated lags
this.updatedSpec = true;
//update listing
updatePilotListing();
this.clsListing.DataSource = this.clsList;
this.specListing.DataSource = this.specList;
dgvPilotListing.DataSource = this.clsListing;
dgvPilotSpec.DataSource = this.specListing;
refreshDGVPilot();
}
private void refreshDGVSpec()
{
this.specListing.ResetBindings(false);
if (dgvPilotSpec.Columns.Count > 0)
{
//do nothing right now
}
}
private void updatePilotSpecLst(SQLiteConnection conn, long classID)
{
this.specList.Clear();
SQLiteCommand getPilotSpec = conn.CreateCommand();
getPilotSpec.CommandText = "SELECT * FROM classSpec WHERE classID = "
+ classID;
SQLiteDataReader rdr = getPilotSpec.ExecuteReader();
while (rdr.Read())
{
this.specList.Add(new pilotSpec(rdr.GetInt64(0), rdr.GetString(1),
txtClassName.Text, rdr.GetInt64(2)));
}
refreshDGVSpec();
}
and pilotSpec is pretty simple:
public class pilotSpec
{
public long pilotSpecID;
public string pilotClassName;
public string pilotSpecName;
public long pilotSpecLevel;
public pilotSpec(long id, string name, string className, long level)
{
this.pilotSpecID = id;
this.pilotClassName = className;
this.pilotSpecName = name;
this.pilotSpecLevel = level;
}
}
I can't figure it out.
No comments:
Post a Comment