11 public partial class Form1 : Form 12 { 13 private static readonly string connectionstr = ConfigurationManager.ConnectionStrings[ " hydb " ].ConnectionString; 15 public Form1() 16 { 17 InitializeComponent(); 18 } 20 private void Form1_Load( object sender, EventArgs e) 21 { 22 // TODO: 这行代码将数据加载到表“huayaDBDataSet.K_City”中。您可以根据需要移动或删除它。 23 this .k_CityTableAdapter.Fill( this .huayaDBDataSet.K_City); 24 BingDataGridview(); 25 } 27 private void BingDataGridview() 28 { 29 using (SqlConnection conn = new SqlConnection(connectionstr)) 30 { 31 conn.Open(); 32 using (SqlDataAdapter ad = new SqlDataAdapter( " select ID,userID,userno ,Optext,Remark from F_OperateLog " , conn)) 33 { 34 using (DataSet set = new DataSet()) 35 { 36 ad.Fill( set ); 37 this .dataGridView1.DataSource = set .Tables[ 0 ].DefaultView; // 绑定数据 38 dataGridView1.MultiSelect = false ; // 单选 39 dataGridView1.Rows[ 1 ].Selected= true ; // 默认第二行为选中的状态 40 } 41 } 42 } 43 } 45 private void dataGridView1_CellClick( object sender, DataGridViewCellEventArgs e) 46 { 47 string id = dataGridView1.CurrentRow.Cells[ 0 ].Value.ToString(); 48 if (! string .IsNullOrEmpty(id)) 49 { 50 // MessageBox.Show($"获取到主键ID={id}"); 51 labshowid.Text = $ " 获取到主键ID={id} " ; 52 } 53 } 54 /// <summary> 55 /// 获取选中行的key ID 56 /// </summary> 57 /// <param name="sender"></param> 58 /// <param name="e"></param> 59 private void BtnSelectID_Click( object sender, EventArgs e) 60 { 61 string id = dataGridView1.CurrentRow.Cells[ 0 ].Value.ToString(); 62 MessageBox.Show($ " dataGridView1.CurrentRow.Cells[0].Value.ToString={id},\n下面就可以使用主键ID的值来CURD的操作 " ); 63 } 64 /// <summary> 65 /// 获取选中行的所有数据 66 /// </summary> 67 /// <param name="sender"></param> 68 /// <param name="e"></param> 69 private void BtnSelectRowData_Click( object sender, EventArgs e) 70 { 72 int rowIndex = dataGridView1.CurrentRow.Index; // 选中当前行的索引 73 int cellCount = dataGridView1.GetCellCount(DataGridViewElementStates.Selected); // 获取一行的列有多少个 75 StringBuilder sb = new StringBuilder(); 76 for ( int i = 0 ; i < cellCount; i++ ) 77 { 78 sb.Append(dataGridView1.CurrentRow.Cells[i].Value.ToString() + " , " ); 79 } 80 MessageBox.Show(sb.ToString().TrimEnd( ' , ' )+ " ,\n\ncellCount= " + cellCount+ " ,rowIndex= " + rowIndex); 81 } 83 private void BtnProStart_Click( object sender, EventArgs e) 84 { 85 for ( int i = 1 ; i < 100 ; i++ ) 86 { 87 this .progressBar1.Value = ( int )(((i + 1 ) / 100.0 ) * 100 ); 88 Application.DoEvents(); 89 int miao = new Random().Next( 1 , 10 ); 90 System.Threading.Thread.Sleep(miao * 10 ); 91 } 92 MessageBox.Show( " 数据加载成功! " , " 请稍后 " , MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk); 93 } 95 private void BtnSubmit_Click( object sender, EventArgs e) 96 { 97 string textboxStr = this .texboxStr.Text; 98 string comboxStr = this .comboBox1.Text; 99 string radiobtnStr = this .radioButton1.Checked == true ? " " : " " ; 100 string textChekboxStr = string .IsNullOrEmpty( this .checkBox1.Text) == true ? "" : this .checkBox1.Text; 101 string textChekboxStr2 = string .IsNullOrEmpty( this .checkBox2.Text) == true ? "" : this .checkBox2.Text; 103 string msg = $ " textboxStr={textboxStr},comboxStr={comboxStr},radiobtnStr={radiobtnStr},textChekboxStr={ textChekboxStr},textChekboxStr2={textChekboxStr2} " ; 104 MessageBox.Show(msg, " 结果是: " ); 105 } 106 } 107 }

View Code

(0)

导读:本篇文章讲解 WPF InkCanvas EditingMode为Select时 在其选择时各种事件中撤销Select模式的方法,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

2022年5月21日 0 0

本文来和大家聊一下关于 XAML 资源的定义的事情,和开发技术关系不大,更多的是开发的思路 在稍微大一点的项目里,肯定 XAML 资源是少不了的。对于 XAML 资源,行业里讨论多…

2022年11月17日 0 0

在 C++ 需要使用 GetSystemFirmwareTable 的方法来获得 PC 的序列号,需要写的代码很多,但是在 **C#**C++ **** 可以使用 WMI 来拿到序…

2022年11月17日 0 0