- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 DataGridview,其中有一个 DataTimePickerColumn
,它是 DateTimePickerCell
包含检查状态。编辑 checkstate 后如何获取 checkstate 值?
最佳答案
创建一个继承自 DateTimePicker 的控件并处理 DTN_DATETIMECHANGE 通知。然后处理你的 DataGridView 的 EditingControlShowing 事件来为你的 DateTimePicker 的新 CheckedChanged 事件添加一个处理程序,或者你甚至可以使用 DateTimePickerEx 作为 EditingControl 创建你自己的 DataGridViewColumn 和 Cell 类型:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public class DateTimePickerEx : DateTimePicker
{
private bool _checked;
private const int WM_REFLECT = 0x2000;
public event CheckedChangedEventHandler CheckedChanged;
public delegate void CheckedChangedEventHandler(object sender, System.EventArgs e);
public DateTimePickerEx()
{
this._checked = this.Checked;
}
private void WmDateTimeChange(ref Message m)
{
NMDATETIMECHANGE nmdatetimechange = m.GetLParam(typeof(NMDATETIMECHANGE));
if (nmdatetimechange.dwFlags == GetDateTimeValues.GDT_NONE) {
if (this.ShowCheckBox && !this.Checked) {
this._checked = false;
if (CheckedChanged != null) {
CheckedChanged(this, EventArgs.Empty);
}
}
} else {
if (this.ShowCheckBox && this.Checked && !this._checked) {
this._checked = true;
if (CheckedChanged != null) {
CheckedChanged(this, EventArgs.Empty);
}
}
this.Value = SysTimeToDateTime(nmdatetimechange.st);
}
m.Result = IntPtr.Zero;
}
private bool WmReflectCommand(ref Message m)
{
if (m.HWnd == this.Handle) {
long code = NMHDR.FromMessage(m).code;
switch (code) {
case FWEx.Win32API.DateTimePickerNotifications.DTN_DATETIMECHANGE:
this.WmDateTimeChange(ref m);
return true;
}
return false;
}
}
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
protected override void WndProc(ref System.Windows.Forms.Message m)
{
if (m.Msg != 71 && m.Msg != 513) {
switch ((WindowsMessages)m.Msg) {
case WindowsMessages.WM_NOTIFY + WM_REFLECT:
if (!this.WmReflectCommand(ref m)) {
break;
}
return;
break;
}
}
base.WndProc(m);
}
private System.DateTime SysTimeToDateTime(SYSTEMTIME st)
{
return new System.DateTime(st.Year, st.Month, st.Day, st.Hour, st.Minute, st.Second);
}
/// <summary>
/// This structure contains information about a change that has taken place in a date and time picker (DTP) control.
/// This structure is used with the DTN_DATETIMECHANGE notification message.
/// </summary>
/// <remarks></remarks>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct NMDATETIMECHANGE
{
/// <summary>
/// NMHDR structure that contains information about the notification message.
/// </summary>
public NMHDR nmhdr;
/// <summary>
/// Specifies if the control was set to no date status (for DTS_SHOWNONE only).
/// Also specifies whether the contents of the st member are valid and contain current time information.
/// </summary>
public GetDateTimeValues dwFlags;
/// <summary>
/// SYSTEMTIME structure that contains information about the current system date and time.
/// </summary>
public SYSTEMTIME st;
}
/// <summary>
/// This structure contains information about a message.
/// The pointer to this structure is specified as the lParam member of the WM_NOTIFY message.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct NMHDR
{
/// <summary>
/// Window handle to the control sending a message.
/// </summary>
public IntPtr hwndFrom;
/// <summary>
/// Identifier of the control sending a message.
/// </summary>
public IntPtr idFrom;
/// <summary>
/// Notification code. This member can be a control-specific notification code or it can be one of the common notification codes. The following values are supported if you include mouse support in your device platform:
/// - NM_RCLICK
/// - NM_RDBCLICK
/// </summary>
public int code;
public static NMHDR FromMessage(System.Windows.Forms.Message msg)
{
return (NMHDR)msg.GetLParam(typeof(NMHDR));
}
}
/// <summary>
/// Specifies a date and time, using individual members for the month, day, year, weekday, hour, minute, second, and millisecond.
/// The time is either in coordinated universal time (UTC) or local time, depending on the function that is being called.
/// </summary>
/// <remarks>
/// It is not recommended that you add and subtract values from the SYSTEMTIME structure to obtain relative times.
/// </remarks>
public struct SYSTEMTIME
{
/// <summary>
/// The year. The valid values for this member are 1601 through 30827.
/// </summary>
public short Year;
/// <summary>
/// The month.
/// </summary>
public short Month;
/// <summary>
/// The day of the week. Sunday = 0.
/// </summary>
public short DayOfWeek;
/// <summary>
/// The day of the month. The valid values for this member are 1 through 31.
/// </summary>
public short Day;
/// <summary>
/// The hour. The valid values for this member are 0 through 23.
/// </summary>
public short Hour;
/// <summary>
/// The minute. The valid values for this member are 0 through 59.
/// </summary>
public short Minute;
/// <summary>
/// The second. The valid values for this member are 0 through 59.
/// </summary>
public short Second;
/// <summary>
/// The millisecond. The valid values for this member are 0 through 999.
/// </summary>
public short Milliseconds;
}
public enum GetDateTimeValues
{
/// <summary>
/// Error.
/// </summary>
GDT_ERROR = -1,
/// <summary>
/// The control is not set to the no date status.
/// The st member contains the current date and time.
/// </summary>
GDT_VALID = 0,
/// <summary>
/// The control is set to no date status.
/// The no date status applies only to controls that are set to the DTS_SHOWNONE style.
/// </summary>
GDT_NONE = 1
}
public enum WindowsMessages
{
/// <summary>
///Sent by a common control to its parent window when an event has occurred or the control requires some information.
/// </summary>
WM_NOTIFY = 0x4e
}
public enum DateTimePickerNotifications
{
DTN_FIRST = -740,
DTN_LAST = -745,
DTN_FIRST2 = -753,
DTN_LAST2 = -799,
DTN_DATETIMECHANGE = DTN_FIRST2 - 6,
DTN_USERSTRING = DTN_FIRST2 - 5,
DTN_WMKEYDOWN = DTN_FIRST2 - 4,
DTN_FORMAT = DTN_FIRST2 - 3,
DTN_FORMATQUERY = DTN_FIRST2 - 2,
DTN_DROPDOWN = DTN_FIRST2 - 1,
DTN_CLOSEUP = DTN_FIRST2
}
}
private void dgv_EditingControlShowing(System.Object sender, System.Windows.Forms.DataGridViewEditingControlShowingEventArgs e)
{
switch (this.dgv.CurrentCellAddress.X) {
case 0: // your DateTimePickerEx column number
DateTimePickerEx dtp = e.Control as DateTimePickerEx;
if (dtp != null) {
dtp.CheckedChanged += (object sen, EventArgs ea) => {
//TODO: Add your code here
};
}
break;
}
}
关于.net - 如何获取DataGridView的DateTimePicker checkstate值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7568513/
我已经看到 Datagridview 不允许复制和粘贴多个单元格的文本,是否有一个简单的设置来启用它,或者我是否必须使用键处理程序和剪贴板数据存储来包含该功能。 用户想要在一行中复制 3 个单元格,并
我有一个 DataGridView我想限制用户只为特定列下的单元格输入数值的控件。我怎样才能在 DataGridView 中完成这种类型的验证细胞? 当我创建一个简单的文本框时是可能的,但是我如何验证
我正在尝试格式化 DataGridView,使用样式颜色等。DGV 在表单启动时加载(通过 buildGrid 方法),如构造函数代码中所示: public Report1(DataSet d
第一列中的小黑三角的官方DataGridView命名法描述是什么? 好像是标记了DataGridView.CurrentRow的位置,但是只是一个get属性,我想设置一下。 Grid with arr
我有点卡在我写的一些代码上 一个大纲是我正在从 SQL 数据库中读取一些数据,并希望将其显示在表单上的 DataGridView 中。我已经确认有数据从数据库返回,但不确定为什么没有出现。我遵循了互联
我的 DataTable从数据库中提取了三列,而我只需要将其中的两列绑定(bind)到 DataGridView .你能帮我吗? 最佳答案 这可能有用 DataSet ds = new DataSet
我有一个包含 Dataset ds 和 DataGridView dgv 的 WinForms 应用程序。 dgv 绑定(bind)到 ds。 ds 通过 Task() 更新,该 Task() 使用
我有DataGridView(dgHome),在parentForm(Home)中有一些列。子 Form(bill) 有 DataGridView(dgbill) 。我需要当我单击 dgHome 中的
我有两个具有相同列架构的 DataGridView(尽管有两个不同的 DataView 作为 DataSource - 如果这很重要)。将一行从一个数据 GridView 移动到另一个数据 GridV
基本上我有 2 个 DataGridView,我需要将行从一个复制到另一个。 到目前为止我已经尝试过: DataGridViewRowCollection tmpRowCollection = Dat
我正在尝试根据它包含的行数使我的 DataGridView 的高度自动调整。目前,我能够通过以下行完成此操作: dataGridView_SearchResults.AutoSize = true;
使用 WinForms、C# .Net 2.0 我正在向非绑定(bind) DataGridView 添加行。我想在其中一列中有一个 DataGridViewButtonColumn,在单击时删除该行
我有一个 datagridview(dataGridView1,其中包含一个 dataGridview2 列标题),其中我有一个复选框列,称为 dgvCkb,在 dataGridView1。当我在任何
对不起,如果这是一个愚蠢的问题。我在这方面很陌生。我应该如何将组合框添加到数据表,然后将其加载到数据 GridView 中?这可以做到吗?这是最好的方法吗?非常感谢有关如何执行此操作的提示和教程。先感
我正在尝试将 .txt 文件导入 DataGrid。问题是虽然代码大部分工作正常,但在导入 .txt 文件时,它会创建额外的行,例如 this ; OpenFileDialog ofd
datagridview 加载速度非常慢。我该如何优化它? datagridview有4-5千行。 我必须根据几个参数动态生成一个 datagridview。(来自数据库的数据,列数) 我必须从数据库
我怎样才能强制DataGridView.CellValueChanged DataGridViewCell.Value 立即引发事件(并将更改实际提交给 ComboBox 属性)单元格中的编辑控件更改
我有一个通过数据集从数据库中获取数据的功能 public DataSet getDataSet(string query) { DataSet ds = new DataSet()
客户希望能够键入一个字母并让系统滚动 DataGridView,这样具有与字母匹配的单元格的第一行将滚动到 DataGridView 的顶部 任何建议将不胜感激 最佳答案 我不确定您将如何有效地查找与
好吧,我有一个 DataGridView,用户可以在其中单击列标题进行排序。当他们在应用排序时添加新行时,直到验证该行时才会创建记录(在退出 newRow 之前他们无法执行此操作)。排序后如何才能选择
我是一名优秀的程序员,十分优秀!