20151210001 DataGridView 选中与被选中
2015-12-10 17:26
519 查看
// DataSet_IP list
private void DataSet_IP_list()
{
DataSet_IP = new System.Data.DataSet();
DataTable tb = new DataTable("Ds_IP");
DataColumnCollection columns = tb.Columns;
columns.Add("IP", typeof(String));
columns.Add("机号", typeof(String));
DataSet_IP.Tables.Add(tb);
Int32 int_ip = dgv_IP2.Rows.Count;
for (int i = 0; i < dgv_IP2.Rows.Count; i++)
{
if (dgv_IP2.Rows[i].Cells[0].EditedFormattedValue.ToString() == "True")
{
//array_ip = new string[] { dgv_IP2.Rows[i].Cells[1].Value.ToString() };
//array_mac = new string[] { dgv_IP2.Rows[i].Cells[2].Value.ToString() };
//MessageBox.Show(dgv_IP2.Rows[i].Cells[2].Value.ToString());
string str1 = dgv_IP2.Rows[i].Cells[1].Value.ToString();
string str2 = dgv_IP2.Rows[i].Cells[2].Value.ToString();
DataRow row = DataSet_IP.Tables[0].NewRow();
row["IP"] = str1.ToString();
row["机号"] = str2.ToString();
DataSet_IP.Tables[0].Rows.Add(row);
}
}
}
//// dgv_IP2 Selected
private void dgv_IP2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//if (e.ColumnIndex == 1)
//{
if (e.ColumnIndex == 0 && e.RowIndex != -1)
{
//DataGridViewCell cell = dgv_IP2.Rows[e.RowIndex].Cells[e.ColumnIndex];
//DataGridViewCell cell = dgv_IP2.Rows[e.RowIndex].Cells[1];
//MessageBox.Show(cell.ToString());
//MessageBox.Show(dgv_IP2.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue.ToString());
if (dgv_IP2.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue.ToString() == "True")
{
str_ip = dgv_IP2.Rows[e.RowIndex].Cells[1].Value.ToString();
connection1();
}
else
{
str_ip = dgv_IP2.Rows[e.RowIndex].Cells[1].Value.ToString();
disconnection1();
}
//
//this.dgv_IP2.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgv_IP2_CellClick);
this.dgv_IP2.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgv_IP2_CellValueChanged);
//dgv_IP2.Rows[e.RowIndex].Cells[0].Value = false;
dgv_IP2.CurrentCell = dgv_IP2[1, 0];
dgv_IP2.BeginEdit(true);
}
}
private void dgv_IP2_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (m_bConnected == false)
{
dgv_IP2.Rows[e.RowIndex].Cells[0].Value = false;
}
else
{
dgv_IP2.Rows[e.RowIndex].Cells[0].Value = true;
}
}
////
private void DataSet_IP_list()
{
DataSet_IP = new System.Data.DataSet();
DataTable tb = new DataTable("Ds_IP");
DataColumnCollection columns = tb.Columns;
columns.Add("IP", typeof(String));
columns.Add("机号", typeof(String));
DataSet_IP.Tables.Add(tb);
Int32 int_ip = dgv_IP2.Rows.Count;
for (int i = 0; i < dgv_IP2.Rows.Count; i++)
{
if (dgv_IP2.Rows[i].Cells[0].EditedFormattedValue.ToString() == "True")
{
//array_ip = new string[] { dgv_IP2.Rows[i].Cells[1].Value.ToString() };
//array_mac = new string[] { dgv_IP2.Rows[i].Cells[2].Value.ToString() };
//MessageBox.Show(dgv_IP2.Rows[i].Cells[2].Value.ToString());
string str1 = dgv_IP2.Rows[i].Cells[1].Value.ToString();
string str2 = dgv_IP2.Rows[i].Cells[2].Value.ToString();
DataRow row = DataSet_IP.Tables[0].NewRow();
row["IP"] = str1.ToString();
row["机号"] = str2.ToString();
DataSet_IP.Tables[0].Rows.Add(row);
}
}
}
//// dgv_IP2 Selected
private void dgv_IP2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//if (e.ColumnIndex == 1)
//{
if (e.ColumnIndex == 0 && e.RowIndex != -1)
{
//DataGridViewCell cell = dgv_IP2.Rows[e.RowIndex].Cells[e.ColumnIndex];
//DataGridViewCell cell = dgv_IP2.Rows[e.RowIndex].Cells[1];
//MessageBox.Show(cell.ToString());
//MessageBox.Show(dgv_IP2.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue.ToString());
if (dgv_IP2.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue.ToString() == "True")
{
str_ip = dgv_IP2.Rows[e.RowIndex].Cells[1].Value.ToString();
connection1();
}
else
{
str_ip = dgv_IP2.Rows[e.RowIndex].Cells[1].Value.ToString();
disconnection1();
}
//
//this.dgv_IP2.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgv_IP2_CellClick);
this.dgv_IP2.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgv_IP2_CellValueChanged);
//dgv_IP2.Rows[e.RowIndex].Cells[0].Value = false;
dgv_IP2.CurrentCell = dgv_IP2[1, 0];
dgv_IP2.BeginEdit(true);
}
}
private void dgv_IP2_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (m_bConnected == false)
{
dgv_IP2.Rows[e.RowIndex].Cells[0].Value = false;
}
else
{
dgv_IP2.Rows[e.RowIndex].Cells[0].Value = true;
}
}
////
相关文章推荐
- 老李案例分享:Weblogic性能优化案例
- Eclipse svn提交代码的一般步骤(对比、解决冲突、更新、提交)
- JAVA配置文件之applicationContext.xml
- c++学习笔记(2)
- Ubuntu安装软件提示"需要安装不能信任的软件包"
- Xcode自动创建时的注释
- Proguard 部分类不混淆的技巧
- 滑雪
- 2015广工新生赛 Problem A: GG和女神
- 以非 root 用户身份使用 Wireshark 抓包(Sniffing with Wireshark as a Non-Root User)
- 初识MariaDB存储引擎
- 156 Identify the persistent configuration setting for the target database that can be set for the ba
- nodejs入门
- linux 程序运行监控
- 老李分享:loadrunner的java user脚本开发
- 一致性哈希算法
- 老李分享:Eclipse中开发性能测试loadrunner脚本
- ProGuard的作用、使用及bug分析
- 155 Which three statements are true about windows? (Choose three.) A. Only one window can be open at
- h5+百度地图获取地理位置