这个直接上代码,操作dataGridView1_CellContentClick的单元格,这里有一点需要注意的是,个人推测可能是由于单元的事件过多,所以在设置操作单元格时只能去点击单元格中的字,否则就不会有响应事件
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//判断选中的有多少
if (dataGridView1.Rows.Count > 0) {
int j =0;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
string _selectValue = dataGridView1.Rows[i].Cells["Column1"].EditedFormattedValue.ToString();
if (_selectValue == "True")
{
j++;
}
}
label5.Text = j.ToString();
}
//当点击词频时排序
if (e.ColumnIndex == 5 && e.RowIndex == -1)
{
if (flag == -1)
{
flag = 1;
}
else
{
flag = -1;
}
if (!string.IsNullOrEmpty(comboBox1.Text))
{
if (comboBox1.Text == "动词")
{
SearchGroup(flag, "v", 1);
label10.Text = 1.ToString();
}
else if (comboBox1.Text == "名词")
{
SearchGroup(flag, "n", 1);
label10.Text = 1.ToString();
}
}
else
{
SearchGroup(flag, "", 1);
label10.Text = 1.ToString();
}
}
else
if (e.ColumnIndex == 6 && e.RowIndex == -1)
{
//词性的下拉框
}
else
if (e.ColumnIndex == 4 && e.RowIndex != -1)
{
words = dataGridView1.Rows[e.RowIndex].Cells["词语"].EditedFormattedValue.ToString();
CompanyGroup(words, 1);
label15.Text = 1.ToString();
}
else if (e.ColumnIndex == 1 && e.RowIndex != -1)
{
string words = dataGridView1.Rows[e.RowIndex].Cells["词语"].EditedFormattedValue.ToString();
Form2 Form2 = new Form2(words, "整体", 20, 1);
Form2.ShowDialog();
}
else if (e.ColumnIndex == 2 && e.RowIndex != -1)
{
//操作
//查询该分组
StringBuilder sql = new StringBuilder();
sql.AppendFormat("select {0} from {1} ", "*", "[dbo].[分词分组表]");
SqlDataAdapter sda = new SqlDataAdapter(sql.ToString(), myConnection);
if (myConnection.State != ConnectionState.Open)
myConnection.Open();
DataTable dt = new DataTable();
sda.Fill(dt);
myConnection.Close();
Fenzu Fenzu = new Fenzu(dt, dataGridView1.Rows[e.RowIndex].Cells["词语"].EditedFormattedValue.ToString());
Fenzu.Show();
}
}
界面如下