簡體   English   中英

C#Datagridview綁定源

[英]c# Datagridview bindingsource

這是我程序的當前片段,它是將datagridview斷開與數據表的連接,因此,如果我更改dataviewgrid上的任何內容,它都不會反映在數據表中...如何進行修改,以便對datagridview可以反映到至少datatable嗎?

        OpenFileDialog OFD = new OpenFileDialog();
        OFD.Title = "CSV File";
        OFD.Filter = "Spreadsheet | *.csv";
        OFD.ShowDialog();

        FileHelperEngine engine = new FileHelperEngine(typeof(csv_SeatingPlan));
        try
        {
            csv_SeatingPlan[] container = engine.ReadFile(OFD.FileName) as csv_SeatingPlan[];
            CSV_Seating_Plan = new List<csv_SeatingPlan>(container);

            DataTable DT_student_Records = new DataTable();
            DT_student_Records.Columns.Add("Exam_Period", typeof(string));
            DT_student_Records.Columns.Add("Exam_Code", typeof(string));
            DT_student_Records.Columns.Add("Student_ID", typeof(string));
            DT_student_Records.Columns.Add("Student_Name", typeof(string));
            DT_student_Records.Columns.Add("Candidate_Number", typeof(string));


            foreach (csv_SeatingPlan row in CSV_Seating_Plan)
            {
                DT_student_Records.Rows.Add(row.examperiod, row.exam_Code, row.id_Student, row.name_Student, row.candidatenum_Student);
            }

            DT_student_Records.DefaultView.Sort = "Candidate_Number ASC";
            this.dataGridView1.DefaultCellStyle.Font = new Font("Tahoma", 11);
            //bindingCSVSP.DataSource = DT_student_Records;
            this.dataGridView1.DataSource = DT_student_Records;

為了將您的更改傳播到基礎數據源(在您的情況下為表),應使用BindingSource對象。 如何執行此操作的示例位於鏈接頁面的底部。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM