[c#]Winform DataGridView 結合 DateTimePicker、NumericUpDown與RadioButton的應用
2013-03-26 10:56
399 查看
小弟最近看到某一元件的samplecode,利用DataGridView結合了DateTimePicker
感覺還不錯用,另外我用此方法在增加了NumericUpDown與RadioButton的整合,分享給大家呀..
c#(winfrom)
MainForm.cs(DateTimePicker範例)
執行結果:
DateTimePicker
NumericUpDown
RadioButton
http://www.dotblogs.com.tw/puma/archive/2008/11/10/5943.aspx
感覺還不錯用,另外我用此方法在增加了NumericUpDown與RadioButton的整合,分享給大家呀..
c#(winfrom)
MainForm.cs(DateTimePicker範例)
01 | using System; |
02 | using System.Collections.Generic; |
03 | using System.ComponentModel; |
04 | using System.Data; |
05 | using System.Drawing; |
06 | using System.Text; |
07 | using System.Windows.Forms; |
08 |
09 | namespace
|
10 | { |
11 | public partial class MainForm:Form |
12 | { |
13 | private bool _CheckChange= false ; |
14 |
15 | public MainForm() |
16 | { |
17 | InitializeComponent(); |
18 | } |
19 |
20 | private void MainForm_Load( object sender,EventArgse) |
21 | { |
22 | //TODO:這行程式碼會將資料載入'database1DataSet.Table1'資料表。您可以視需要進行移動或移除。 |
23 | this .table1TableAdapter.Fill( this .database1DataSet.Table1); |
24 |
25 | //設定DateTimePicker的高度 |
26 | this .dateTimePicker1.Height= this .dataGridView1.Height; |
27 | } |
28 |
29 | //將DateTimePicker控制項定位在DataGridView的Column上 |
30 | private void dataGridView1_CellEnter( object sender,DataGridViewCellEventArgse) |
31 | { |
32 | if ( this .dataGridView1.Columns[e.ColumnIndex].HeaderText== "date" ) |
33 | { |
34 | Rectangler= this .dataGridView1.GetCellDisplayRectangle(e.ColumnIndex,e.RowIndex, false ); |
35 | r= this .dataGridView1.RectangleToScreen(r); |
36 | this .dateTimePicker1.Location= this .RectangleToClient(r).Location; |
37 | this .dateTimePicker1.Size=r.Size; |
38 | this ._CheckChange= true ; |
39 | this .dateTimePicker1.Text= this .dataGridView1.CurrentCell.Value.ToString(); |
40 | this ._CheckChange= false ; |
41 | this .dateTimePicker1.Visible= true ; |
42 | } |
43 | else |
44 | { |
45 | this .dateTimePicker1.Visible= false ; |
46 | } |
47 | } |
48 |
49 | //改變Column的值 |
50 | private void dateTimePicker1_ValueChanged( object sender,EventArgse) |
51 | { |
52 | if (_CheckChange) return ; |
53 | this .dataGridView1.CurrentCell.Value= this .dateTimePicker1.Text; |
54 | } |
55 | } |
56 | } |
DateTimePicker
NumericUpDown
RadioButton
相关文章推荐
- C# winform DataGridView DateTimePicker 控件
- winform 在datagridview中使用 combobox,datetimepicker
- (C#)Winform修改DateTimePicker控件的背景色Winform中日期控件DateTimePicker默认是不能修改背景色和边框色的
- c# winform 关于DataGridView的一些操作
- c# winform datagridview 控件 删除最左边一列
- c# winform DataGridView单击选中一整行,只能单选,不能选择多行,只能选择一行
- C# WinForm开发系列 - DataGridView
- C#Winform基础 显示datagridview有多少行,有多少列
- C# Winform DataGridView 公共分页实现
- C# Winform DataGridView使用总结 - 转
- C# Winform DataGridView 公共分页实现
- C# Winform中的DataGridView中行定位-滚动条定位
- c# WinForm开发 DataGridView控件的各种操作总结
- c# winform 之DataGridViewComboBoxColumn的使用
- C# WinForm开发系列 - DataGridView 使用方法集锦
- c# winform 用代码修改DataGridView列头的名字,设置列名,修改列名
- C# WinForm下DataGridView绘制背景图
- C# Winform 数据库读取显示dataGridView 列标题的自定义
- C#WinForm程序的DataGridView控件,e.Handled = true
- C#开发——winform中将Excel数据导入DataGridView