0 امتیاز
باسلام و عرض خسته نباشید

چگونه می توان تعداد چک باکس های تیک خورده یک ردیف از دیتاگریدویو را در تکس باکس نشان داد (چند تا تیک خورده)

لطفا راهنمایی کنید

3 پاسخ

0 امتیاز
using System;
using System.Windows.Forms;

namespace WindowsFormsApplication8
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private int getCheckRows(){
            int result = 0;

            for (int rowCounter = this.dataGridView1.Rows.Count -1; rowCounter >=0; rowCounter--)
            {
                if (Convert.ToBoolean(this.dataGridView1.Rows[rowCounter].Cells[1].Value) == true)
                {
                    result++;
                }
            }
            return result;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.dataGridView1.Rows.Add("Siavash", true);
            this.dataGridView1.Rows.Add("Soroush", false);
            this.dataGridView1.Rows.Add("Amin", false);
            this.dataGridView1.Rows.Add("siavash", true);
            this.dataGridView1.Rows.Add("Siavash", true);
            this.dataGridView1.Rows.Add("Soroush", false);
            this.dataGridView1.Rows.Add("Amin", false);
            this.dataGridView1.Rows.Add("siavash", true);

            this.label1.Text = getCheckRows().ToString();
        }

        private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            int count = this.getCheckRows();
            if (count > 4 && Convert.ToBoolean(this.dataGridView1.CurrentCell.Value) == false)
            {
                e.Cancel = true;                     
            }
        }

        private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            if (dataGridView1.IsCurrentCellDirty)
            {
                this.dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
            }
        }

        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            int countRowChecked = getCheckRows();
            this.label1.Text = countRowChecked.ToString();
        }
    }
}

 

Datagrid


 
0 امتیاز
using System;
using System.Windows.Forms;

namespace WindowsFormsApplication18
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.dataGridView1.Rows.Add("amin", false);
            this.dataGridView1.Rows.Add("soroush", false);
            this.dataGridView1.Rows.Add("younes", false);
            this.dataGridView1.Rows.Add("siavash", false);
        }

        
        private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            if (this.dataGridView1.IsCurrentCellDirty)
            {
                this.dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
            }
        }
        
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            int total = 0;
            for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
            {
                if (Convert.ToBoolean(this.dataGridView1.Rows[i].Cells[1].Value) == true)
                {
                    total++;
                }
            }
            this.textBox1.Text = total.ToString();
        }       
    }
}

 

0 امتیاز
با سلام ممنون از لطفتون ولی هر دو کد را امتحان کردم خطا میده

برنامه من حضور غیاب کلاسی هست که 31 ستون داره و ردیف ها هر چند تا بخواهیم اضافه میشه

درست برعکس شکل های پایین تیک ها در ردیف قرار می گیرند

لطفا بیشتر راهنمایی کنید ممنون از لطفتون
چه خطایی می ده ؟ کد خطایی نداره . احتمالا اندیسی چیزی اشتباه دادین .
توسط (6,145 امتیاز) 5 11 116
این خطا رو میده

A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll

Additional information: Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.

If there is a handler for this exception, the program may be safely continued.
توسط (113 امتیاز) 1 1 5
ستون تیک رو به صورت دستی اضافه کردین یا یکی از ستون های موجود در پایگاه داده هست ؟
توسط (6,145 امتیاز) 5 11 116
ستون ها سی و یک ستون چک باکس داخل پایگاه داده هست
توسط (113 امتیاز) 1 1 5
ستون  Checkbox رو به صورت دستی به DGV اضافه کنید . و بر روی این ستون جدید عملیات مورد نظر رو انجام بدین .
توسط (6,145 امتیاز) 5 11 116
سوال جدید

2,337 سوال

2,871 پاسخ

3,725 دیدگاه

3,921 کاربر

دسته بندی ها

...