SQL 2
来源:互联网 发布:猪八戒淘宝收藏有用吗 编辑:程序博客网 时间:2024/05/18 23:53
//在datagridview中添加复选框
private:System::Collections::Generic::Dictionary<int, bool> MyCheckStates;//创建表示键和值的集合
private:void UpdateStatuesBar(){
int MyCount = 0;
for each(bool IsChecked in MyCheckStates.Values){
if(IsChecked)
MyCount++;
}
this->toolStripStatusLabel1->Text = "当前选择的记录条数:" + MyCount.ToString(System::Globalization::CultureInfo::CurrentUICulture);//根据本地区域习惯格式化字符串
}
//打开数据库
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
try{
this->sqlConnection1 = gcnew SqlConnection ("Data Source=CZ;Initial Catalog=mysql2005;User ID=sa;Password=jianxin198563;Integrated Security =SSPI;Asynchronous Processing=True");
this->sqlConnection1->Open();
this->sqlCommand1 = gcnew SqlCommand("select * from Character", sqlConnection1);
//this->sqlDataAdapter1->SelectCommand = this->sqlCommand1;
IAsyncResult^ MyResult = this->sqlCommand1->BeginExecuteReader();
while(MyResult->IsCompleted){
System::Threading::Thread::Sleep(10);
}
SqlDataReader^ MyReader = this->sqlCommand1->EndExecuteReader(MyResult);
DataTable^ MyTable = gcnew DataTable();
MyTable->Load(MyReader);
this->sqlDataAdapter1->SelectCommand = this->sqlCommand1;
this->sqlDataAdapter1->Fill(this->dataSet1,"Character");
this->dataGridView1->DataSource = MyTable;
}
catch(Exception^ eee){
MessageBox::Show(eee->Message, "", MessageBoxButtons::OK, MessageBoxIcon::Information);
}
finally{
this->sqlConnection1->Close();
}
}
private: System::Void dataGridView1_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
if(this->dataGridView1->CurrentCellAddress.X != 0){//获取单元格的行和列索引 即如果点击的单元格不是表格的第0行
if(e->KeyCode == Keys::Space){ //按下空格键
bool checkedValue = (bool)dataGridView1->Rows[dataGridView1->CurrentCellAddress.Y]->Cells[0]->Value;
this->dataGridView1->Rows[dataGridView1->CurrentCellAddress.Y]->Cells[0]->Value = !checkedValue;
//对单元格所在行的第一个单元格的值取反
}
}
}
private: System::Void dataGridView1_CellContentClick(System::Object^ sender, System::Windows::Forms::DataGridViewCellEventArgs^ e) {
if(e->ColumnIndex == 0)//如果点击第0列的单元格
dataGridView1->Rows[e->RowIndex]->Cells[0]->Value = (bool)dataGridView1->Rows[e->RowIndex]->Cells[0]->EditedFormattedValue;
//则将此单元格的值初始化
}
private: System::Void dataGridView1_CellValueChanged(System::Object^ sender, System::Windows::Forms::DataGridViewCellEventArgs^ e) {
if(e->ColumnIndex == 0 && e->ColumnIndex != -1){ //如果数据表不存在或为空
int MyFirstColumn = (int)dataGridView1->Rows[e->RowIndex]->Cells[1]->Value;
MyCheckStates[MyFirstColumn] = (bool)dataGridView1->Rows[e->RowIndex]->Cells[0]->Value;
this->UpdateStatuesBar();
}
}
private: System::Void dataGridView1_CellValueNeeded(System::Object^ sender, System::Windows::Forms::DataGridViewCellValueEventArgs^ e) {
if(e->ColumnIndex == 0){
int MyFirstColumn = (int)dataGridView1->Rows[e->RowIndex]->Cells[1]->Value;
if(MyCheckStates.ContainsKey(MyFirstColumn)) //确定MyCheckStates集合中是否包含本行 ContainsKey方法确定 Control.ControlCollection创建的对象 是否包含具有指定键的项。
e->Value = MyCheckStates[MyFirstColumn];//e->Value用于获取或设置发生此事件的单元格的值。
else
e->Value = nullptr;
}
private: System::Void dataGridView1_CellValuePushed(System::Object^ sender, System::Windows::Forms::DataGridViewCellValueEventArgs^ e) {
if(e->ColumnIndex == 0){
int MyFirstColumn = (int)dataGridView1->Rows[e->ColumnIndex]->Cells[1]->Value; //返回单元格的所在行的checkbox的值
if(!MyCheckStates.ContainsKey(MyFirstColumn)) //如果MyCheckStates集合中不包含本行
MyCheckStates.Add(MyFirstColumn, (bool)e->Value); //在MyCheckStates集合中添加此行的状态
else
MyCheckStates[MyFirstColumn] = (bool)e->Value; //否则只更新此行的状态
}
}
private: System::Void dataGridView1_DataBindingComplete(System::Object^ sender, System::Windows::Forms::DataGridViewBindingCompleteEventArgs^ e) {
dataGridView1->AutoResizeColumn(DataGridViewAutoSizeColumnMode::AllCells); //根据单元格内容调整列宽
}
- sql 2
- SQL 2
- SQL--2
- SQL 2
- sql 2
- sql 2
- SQL(2)
- SQL(2)
- sql 2
- SQL(2)
- SQL(2)
- [SQL]提升SQL执行效率诀窍2-优化SQL语句
- PL/SQL学习笔记[2]-SQL语句
- sql语句-sql学习笔记2
- sql学习笔记(2)----------SQL语法
- SQL Server系列(2)--T-SQL语句
- SQL(2) -- SQL性能优化[未完成]
- SQL--2常用sql语句&实例
- .NET(C#)连接各类数据库代码-集锦
- RGB565和RGB555位图显示
- “软件中国”2008年度获奖作品名单新鲜出炉
- VORC的PE仿真问题之三:符号判断位选择错误导致电路死锁
- 为什么C++里所有类型的变量都一整型输出???请高手帮忙, 谢谢啦!!!!
- SQL 2
- 答qdjdl 问:我在回调函数中想获取参数的值,如何实现?
- 视频捕获软件开发完全教学(作者:不详)
- 2008年网游业收入逾183亿元远超传统三大娱乐业
- Oracle如何快速查找第N条记录?
- [海外生活]人工流产在美国(图)
- 基于视觉的高速寻线机器人设计与实现
- "世界最好工作"候选人公布 3名中国人入选前50
- 两个表的关联