datagridview内にcheckboxを表示させ、checkの入っているものを印刷する機能を実装しています。チェックが入ったかどうかをDictionary<T>(キー(string)と値(bool))を入れて利用しています。
しかし、そのDictionary<T>にキーと値が入っておらず、上手く動かない状況です。どこがどう悪いのかも、正直見当が付きません。
まだC#の学習を始めたばかりで、今回の質問でも必要な情報が抜けているかもしれませんが、ご指摘いただければ助言いただくのに情報を随時挙げていきますので、宜しくお願いします。
C#
1private Dictionary<string, bool> _dicList = new Dictionary<string, bool>(); 2 3private void SetSelectedPrintDocument() { 4 this._printString.Clear(); 5 for (int row = 0; row < this.dataGridViewMain.RowCount; row++) { 6 string key = this.dataGridViewMain[ID_INDEX, row].Value.ToString(); 7 if (this._dicList[key] == true) { 8 this.CreateLabel(this.dataGridViewMain, row); 9 } 10 } 11 this._printStringIndex = 0; 12 this.printDocument1.DocumentName = ApplicationName + "Checked Record"; 13} 14 15private void ToolStripMenuItemFileSelectedPrintPreview_Click(object sender, EventArgs e) { 16 PrintPreviewDialog p = this.printPreviewDialog1; 17 p.Width = this.Width - 100; 18 p.Height = this.Height - 100; 19 SetSelectedPrintDocument(); 20 p.ShowDialog(); 21}
_dicListに値をセットする処理はこちらになります。
C#
1private void dataGridViewMain_CurrentCellDirtyStateChanged(object sender, EventArgs e) { 2 try { 3 if (this.dataGridViewMain.CurrentCellAddress.X == CHECKBOX_INDEX && this.dataGridViewMain.IsCurrentCellDirty) { 4 this.dataGridViewMain.CommitEdit(DataGridViewDataErrorContexts.Commit); 5 } 6 } 7} 8 9private void dataGridViewMain_CellValueChanged(object sender, DataGridViewCellEventArgs e) { 10 if (e.ColumnIndex == CHECKBOX_INDEX && e.RowIndex >= 0) { 11 string check = this.dataGridViewMain[CHECKBOX_INDEX, e.RowIndex].Value.ToString(); 12 string key = this.dataGridViewMain[ID_INDEX, e.RowIndex].Value.ToString(); 13 if (check == true.ToString()) { 14 this._dicList[key] = true; 15 } 16 else { 17 this._dicList[key] = false; 18 } 19 } 20}
_dicListに値をセットする処理が見当たりませんが?