0

SQLite データベースからデータを取得しようとしていますが、最初の DGV は正常に読み込まれますが、2 番目の DGV は読み込まれません。デバッグすると、次のようになります。

-現在の 'this.specListing.Current' は、タイプ 'System.IndexOutOfRangeException' オブジェクト {System.IndexOutOfRangeException} の例外をスローしました

this.specListing は BindingSource です。より具体的なエラーは「インデックス -1 に値がありません」であり、2 つの項目があります (カウント: 2)

コードは次のとおりです。

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();
    }

そして pilotSpec はとてもシンプルです:

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;
    }
}

私はそれを理解することはできません。

4

1 に答える 1

1

グリッドの更新方法を次のように更新できますか。

private void refreshDGVSpec()
{
    CurrencyManager currencyManager = (CurrencyManager)this.BindingContext[dgvPilotSpec.DataSource];
    currencyManager.Refresh();
}

編集:クラスメンバーにはパブリックプロパティが必要です:

変更public long pilotSpecID; public long PilotSpecID { get; set; }

すべてのパブリック メンバー変数に対して同じことを行います。

于 2013-09-10T04:46:19.250 に答える