2016-08-23 2 views
0

일부 솔루션을 사용해 본 끝에 완료하지 못했습니다. access.mdb 파일을 읽었으며 datagridview를 채우고 있습니다. 그런 다음 checkboxcolumn을 추가합니다. 작업이 완료되면 일부 확인란을 선택할 수 있으며 설정에 저장됩니다. 그러나 프로그램을 다시 시작하면 체크 상자의 값이 설정되지만 그 값은 표시되지 않습니다. 나는 dataGridView.Refresh(), dataGridView.EndEdit() 등을 시도했다. 내 실수는 어디 있고 내가 누락 된 부분은 무엇입니까?데이터를로드 한 후 DataGridViewCheckboxCell이 업데이트되지 않습니다.

public partial class Form1 : Form { 

    private List<int> listCheckedColumn = new List<int>(); 
    private List<string> listNewNames = new List<string>(); 

    public Form1() { 
     InitializeComponent(); 
     //Properties.Settings.Default.Reset(); //fürs debugging 
     if (!Properties.Settings.Default["pathOpenings"].Equals("leer") && !Properties.Settings.Default["pathProfiles"].Equals("leer")) { 
      loadOutputData(); 
      //update RESULT Tabelle 
     } 
     if (!Properties.Settings.Default["naSysID"].Equals("leer")) { 
      updateListCheckedColumnFromSettings(); 
      updateCheckboxes(); 
      //update die RESULT Tabelle 
     } 
     if (!Properties.Settings.Default["newNames"].Equals("leer")) { 
      //fülle die new name Liste 
      //fülle die zellen mit infos 
      //update die RESULT Tabelle 
     } 
    } 

    private void updateCheckboxes() { 
     foreach (int value in listCheckedColumn) { 
      int rowIndex = getRowIndexWithValueX(value); 
      if (Convert.ToInt32(dataGridView3.Rows[rowIndex].Cells["SystemID"].Value) == value) { 
       DataGridViewCheckBoxCell checkbox = (DataGridViewCheckBoxCell)dataGridView3.Rows[rowIndex].Cells["Nicht beachten"]; 
       checkbox.Value = checkbox.TrueValue; 
       MessageBox.Show("Row:" + checkbox.RowIndex + " Column:" + checkbox.ColumnIndex); 
      } 
     } 
    } 

    ... 

    ... 

    /// <summary> 
    /// 
    /// </summary> 
    internal void loadOutputData() { 
     var connOpenings = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Properties.Settings.Default["pathOpenings"] + ";"); 
     var connProfiles = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Properties.Settings.Default["pathProfiles"] + ";"); 

     ... 

     // 
     // System aka System Names Table 
     // 
     var sysNames = new DataTable(); 
     var adapterSysNames = new OleDbDataAdapter("SELECT SystemID, SystemName FROM Systems;", connProfiles); 
     adapterSysNames.Fill(sysNames); 
     dataGridView3.DataSource = sysNames; 
     dataGridView3.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; 
     dataGridView3.Sort(dataGridView3.Columns[0], ListSortDirection.Ascending); 
     DataGridViewCheckBoxColumn checkedColumn = new DataGridViewCheckBoxColumn(); 
     checkedColumn.Name = "Nicht beachten"; 
     checkedColumn.FalseValue = false; 
     checkedColumn.TrueValue = true; 
     dataGridView3.Columns.Add(checkedColumn); 
     dataGridView3.CellValueChanged += new DataGridViewCellEventHandler(dataGridView3_CellValueChanged); 
     dataGridView3.CurrentCellDirtyStateChanged += new System.EventHandler(dataGridView3_CurrentCellDirtyStateChanged); 
    } 

    ... 

    private void dataGridView3_CellValueChanged(object sender, DataGridViewCellEventArgs e) { 
     if (e.ColumnIndex == dataGridView3.Columns["Nicht beachten"].Index) { 
      int cellValue = Convert.ToInt32(dataGridView3.Rows[e.RowIndex].Cells["SystemID"].Value); 
      DataGridViewCheckBoxCell checkbox = (DataGridViewCheckBoxCell)dataGridView3.Rows[e.RowIndex].Cells["Nicht beachten"]; 

      if (checkbox.Value == checkbox.TrueValue) { 
       if (!isInList(listCheckedColumn, cellValue)) { 
        listCheckedColumn.Add(cellValue); 
        listCheckedColumn.Sort(); 
        Properties.Settings.Default["naSysID"] = makeStringFromIntList(); 
        Properties.Settings.Default.Save(); 
       } 
      } else { 
       if (isInList(listCheckedColumn, cellValue)) { 
        listCheckedColumn.Remove(cellValue); 
        listCheckedColumn.Sort(); 
        Properties.Settings.Default["naSysID"] = makeStringFromIntList(); 
        Properties.Settings.Default.Save(); 
       } 
      } 
     } 

     foreach (DataGridViewRow row in dataGridView3.Rows) { 
      DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)row.Cells["Nicht beachten"]; 
      if (chk.Value == chk.TrueValue) { 
       MessageBox.Show("Checked- Row: " + chk.RowIndex + " Column: " + chk.ColumnIndex); 
      } 
     } 
    } 

    ... 

    private void dataGridView3_CurrentCellDirtyStateChanged(object sender, EventArgs e) { 
     if (dataGridView3.IsCurrentCellDirty && dataGridView3.CurrentCell.ColumnIndex == dataGridView3.Columns["Nicht beachten"].Index) { 
      dataGridView3.CommitEdit(DataGridViewDataErrorContexts.Commit); 
     } 
    } 

    ... 

    ... 
} 

답변

1

dataGridView.Update()으로 해 보았습니까? 그게 효과가 있을지도 몰라.

+0

내일 시도하고 알려 드리겠습니다. – vandyke

+0

답장을 보내 주셔서 감사합니다. 'dataGridView.Update()'도'dataGridView.UpdateCellVallue (int columnIndex, int rowIndex)'도 – vandyke

+0

mm입니다.'Update()'와'Refresh()'를 함께 사용해보십시오. 'datagridview.Update(); datagridview.Refresh();' –

관련 문제