csharpdoost
دوشنبه 15 آذر 1400, 20:47 عصر
دوستان سلام.
طبق کد زیر بدون مشکل یک ستون چک باکس به دیتاگرید اضافه میشه. اما مشکل اینجاست که میخوام به تعداد مشخص مثلا n تا چک باکس اون هم از ردیف مشخص مثلا از ردیف5 این چک باکسها به ستون اضافه بشن. این کد تمام ردیف ها رو چک باکس میذاره. ممنون
//Find the Location of Header Cell.
System.Drawing.Point headerCellLocation = this.dataGridView1.GetCellDisplayRectangle(0, -1, true).Location;
//Place the Header CheckBox in the Location of the Header Cell.
headerCheckBox.Location = new System.Drawing.Point(headerCellLocation.X + 75, headerCellLocation.Y + 2);
headerCheckBox.BackColor = Color.White;
headerCheckBox.Size = new Size(18, 18);
//Assign Click event to the Header CheckBox.
headerCheckBox.Click += new EventHandler(HeaderCheckBox_Clicked);
dataGridView1.Controls.Add(headerCheckBox);
//Add a CheckBox Column to the DataGridView at the first position.
DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();
checkBoxColumn.HeaderText = "";
checkBoxColumn.Width = 30;
checkBoxColumn.Name = "checkBoxColumn";
dataGridView1.Columns.Insert(0, checkBoxColumn);
طبق کد زیر بدون مشکل یک ستون چک باکس به دیتاگرید اضافه میشه. اما مشکل اینجاست که میخوام به تعداد مشخص مثلا n تا چک باکس اون هم از ردیف مشخص مثلا از ردیف5 این چک باکسها به ستون اضافه بشن. این کد تمام ردیف ها رو چک باکس میذاره. ممنون
//Find the Location of Header Cell.
System.Drawing.Point headerCellLocation = this.dataGridView1.GetCellDisplayRectangle(0, -1, true).Location;
//Place the Header CheckBox in the Location of the Header Cell.
headerCheckBox.Location = new System.Drawing.Point(headerCellLocation.X + 75, headerCellLocation.Y + 2);
headerCheckBox.BackColor = Color.White;
headerCheckBox.Size = new Size(18, 18);
//Assign Click event to the Header CheckBox.
headerCheckBox.Click += new EventHandler(HeaderCheckBox_Clicked);
dataGridView1.Controls.Add(headerCheckBox);
//Add a CheckBox Column to the DataGridView at the first position.
DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();
checkBoxColumn.HeaderText = "";
checkBoxColumn.Width = 30;
checkBoxColumn.Name = "checkBoxColumn";
dataGridView1.Columns.Insert(0, checkBoxColumn);