110,533
社区成员
发帖
与我相关
我的任务
分享
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0 && e.RowIndex != -1)
{
TransportOrderFullSDO data = bindingSource.Current as TransportOrderFullSDO;
if (Convert.ToBoolean(dataGridView.Rows[e.RowIndex].Cells["Check"].EditedFormattedValue) == true)
{
String VehicleNeedName = data.VehicleNeed.ToString();
Guid CompanyID = data.Company_ID;
foreach(DataGridViewColumn col in dataGridView.Columns)
{
if (col.HeaderText != "选择")
continue;
for (int k = 0; k < dataGridView.RowCount; k++)
{
Guid id = new Guid(dataGridView.Rows[k].Cells[1].Value.ToString());
if (id == CompanyID)
{
if (col.HeaderText == "运输方式")
{
if (dataGridView.Rows[k].Cells[col.Index].EditedFormattedValue.ToString() == VehicleNeedName)
dataGridView.Rows[k].Cells[0].ReadOnly = false;
else
dataGridView.Rows[k].Cells[0].ReadOnly = true;
}
}
else
{
dataGridView.EndEdit();
dataGridView.Rows[k].Cells[0].ReadOnly = true;
if(dataGridView.Rows[k].Cells[0].ReadOnly == true)
dataGridView.Rows[k].Cells[0].Style.BackColor = Color.Red;
else
dataGridView.Rows[k].Cells[0].Style.BackColor = Color.Blue; }
}
}
}
else if (Convert.ToBoolean(dataGridView.Rows[e.RowIndex].Cells["Check"].EditedFormattedValue) == false)//不选中
{
//........
}
}
}
if(dataGridView.Rows[k].Cells[0].ReadOnly == true)
{
dataGridView.Rows[k].Cells[0].Style.BackColor = Color.Red;
dataGridView.Rows[k].Cells[0].ReadOnly = false;
}
else
dataGridView.Rows[k].Cells[0].Style.BackColor = Color.Blue;
for(int index=0;index<dataGridView1.Rows.Count;index++)
{
this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = (index == e.RowIndex);
}