110,533
社区成员
发帖
与我相关
我的任务
分享
private void button3_Click(object sender, EventArgs e)
{
int count = 0;
for (int i = 0; i <this.dataGridView2 .Rows.Count; i++)
{
string _selectValue =this.dataGridView2 .Rows[i].Cells[0].EditedFormattedValue.ToString();
if (_selectValue == "True")
{
count++;
}
}
string [] photoPointX = new string [count];
for (int i = 0; i < this.dataGridView2.Rows.Count; i++)
{
string _selectValue = this.dataGridView2.Rows[i].Cells[0].EditedFormattedValue.ToString();
if (_selectValue == "True")
{
photoPointX[i] = this.dataGridView2.Rows[i].Cells["ctrlPointX"].EditedFormattedValue.ToString();
}
}
for (int i = 0; i < photoPointX .Length; i++)
{
this.textBox1.Text = this.textBox1.Text +photoPointX [i] ;
}
MessageBox.Show(Convert.ToString(count));
}
private void button3_Click(object sender, EventArgs e)
{
int count = Convert.ToInt32(dataGridView1.Rows.Count.ToString());
for (int i = 0; i < count; i++)
{
DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells["photoPointX"];
Boolean flag = Convert.ToBoolean(checkCell.Value);
if (flag == true) //查找被选择的数据行
{
checkCell.Value = false;
}
else
continue;
}
string[] photoPointX = { };
for (int i = 0; i < count; i++)
{
//如果DataGridView是可编辑的,将数据提交,否则处于编辑状态的行无法取到
dataGridView1.EndEdit();
DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells["photoPointX"];
Boolean flag = Convert.ToBoolean(checkCell.Value);
if (flag == true) //查找被选择的数据行
{
//从 DATAGRIDVIEW 中获取数据项
photoPointX[i] = dataGridView1.Rows[i].Cells[0].Value.ToString().Trim();
}
}
for(int i=0;i<photoPointX .Length -1;i++)
{
this.textBox1.Text = this.textBox1.Text + photoPointX[i];
}
}
if (e.ColumnIndex == 0 && e.RowIndex != -1)
{
//获取控件的值
MessageBox.Show(
"X:" + this.dataGridView1.Rows[e.RowIndex].Cells["x"].EditedFormattedValue.ToString() +
"\n\r" +
"Y:" + this.dataGridView1.Rows[e.RowIndex].Cells["y"].EditedFormattedValue.ToString(),
this.dataGridView1.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString());
//或者可以做其他事件处理程序
}