C# DataGridView 手動新增/刪除/全選/取消全選(沒有DB)

C# DataGridView 手動新增/刪除/全選/取消全選(沒有DB)

C# DataGridView 手動新增/刪除/全選/取消全選(沒有DB)


code

    private void butSub000001_01_Click(object sender, EventArgs e)//手動新增假日到DataGridView
    {
        String StrName = txtSub000001_05.Text;
        String StrDate = String.Format("{0:00}/{1:00}", dtpSub000001_01.Value.Month, dtpSub000001_01.Value.Day);
        this.dgvSub000001_01.Rows.Add(false,StrName, StrDate);//利用開發工具新增三個欄位(bool,txt,txt)
    }
	
    private void butSub000001_04_Click(object sender, EventArgs e)//全選
    {
        for(int i=0;i<dgvSub000001_01.Rows.Count;i++)
        {
            dgvSub000001_01.Rows[i].Cells[0].Value = true;
        }
    }
	
    private void butSub000001_05_Click(object sender, EventArgs e)//取消全選
    {
        for (int i = 0; i < dgvSub000001_01.Rows.Count; i++)
        {
            dgvSub000001_01.Rows[i].Cells[0].Value = false;
        }
    }
	
    private void butSub000001_06_Click(object sender, EventArgs e)//刪除全選
    {
        for (int i = 0; i < dgvSub000001_01.Rows.Count; i++)
        {
            String data = dgvSub000001_01.Rows[i].Cells[0].Value.ToString().ToLower();//抓取DataGridView欄位資料
            if (data == "true")
            {
                DataGridViewRow r1 = this.dgvSub000001_01.Rows[i];//取得DataGridView整列資料
                this.dgvSub000001_01.Rows.Remove(r1);//DataGridView刪除整列
            }
        }
        for (int i = 0; i < dgvSub000001_01.Rows.Count; i++)
        {
            String data = dgvSub000001_01.Rows[i].Cells[0].Value.ToString().ToLower();//抓取DataGridView欄位資料
            if (data == "true")
            {
                DataGridViewRow r1 = this.dgvSub000001_01.Rows[i];//取得DataGridView整列資料
                this.dgvSub000001_01.Rows.Remove(r1);//DataGridView刪除整列
            }
        }

    }

 

 

 

 

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *