- 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/
PyQt6 文档说 Qt.CheckState.Unchecked == 0 和 Qt.CheckState.Checked == 2。 我写了一个小程序来测试这一点,但结果完全不同。 程序代码如下:
我做了一个扩展方法来交换 CheckedListBox 中两个项目的位置。该方法放在静态 Utilities 类中。问题是 CheckState 不会移动。因此,如果我在列表中向上移动一个选中的项目,
使用 checkState 相对于断言有什么好处吗?我记得在某处读过我应该更喜欢 checkState 但我不记得为什么。 最佳答案 checkState 和 assert 具有完全不同的目的。 ch
我有一堂这样的课: public class TimerActivity extends Activity { CountDownTimer cntTimer = null; @Override pr
我想在 QSetting 中保存 QCheckBok 的状态,我可以将它的值转换为 int 但也许存在更简单和适当的方法来做到这一点? 这是我的代码: QSetting setting; Qt::Ch
我已经创建了一个 Guava(一个包含有用的东西的库,几乎可以在任何 Java 项目中使用,包括用于不可变集合、函数式编程、I/O 等等的库)基于 CacheBuilder 的缓存 LoadingC
我正在使用 C# 开发一个 WinForms 应用程序,代码如下: ((CheckBox)page.Controls[check_box_name]).CheckState = CheckState.
我正在寻找 CheckedListBox 的事件,该事件在项目的选中状态更改后触发。 ItemCheckEventHandler 对我不利,因为它会在应用新状态之前触发。 谢谢! 最佳答案 如果您要查
本文整理了Java中org.apache.tomcat.websocket.WsSession.checkState()方法的一些代码示例,展示了WsSession.checkState()的具体用法
谁能告诉我使用 checkboxes 选中属性与 CheckState 属性进行数据绑定(bind)的优缺点? 谢谢。 最佳答案 Checked 只能是真或假(显示复选标记或无),而 CheckSta
我在程序中找不到此问题的解决方案:我使用 JMRTD 库创建并个性化 JCOP 卡,但是在完成后,向服务发送关闭命令,然后再次插入卡,任何尝试执行任何操作都会返回卡已断开连接的信息。我是否缺少重置标志
我需要将 int 和/或 bool 转换为 checkState int ValueCheck; private void gsCheck1_CheckedChanged(object se
我在处理选中的列表框时偶然发现了 SetItemChecked 和 SetItemCheckState。 SetItemChecked 采用列表索引和 True/false 来将列表项设置为选中或取消
我正在尝试设置 Android 项目,但出现以下错误。 Unable to find method 'com.google.common.base.Preconditions.checkState(Z
我将 Apache Beam 与 Cloud Dataflow Runner 一起使用,并在尝试运行管道时出现以下异常: java.lang.NoSuchMethodError: com.google
我正在尝试将 Selenium api 与 Gradle 一起使用。这是我的 build.gradle 依赖部分: dependencies { compile 'com.google.api
我正在尝试将 Selenium api 与 Gradle 结合使用。这是我的 build.gradle 依赖部分: dependencies { compile 'com.google.api
我开发的 Selenium 代码: import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; i
我有一个 TestNG 测试,在 Eclipse 中作为 TestNG Suite 运行时可以按预期工作,但通过命令行运行时会失败。我看到无法启动浏览器的问题,但类路径设置工作正常,因为我刚刚打印了h
出现以下错误: java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/Str
我是一名优秀的程序员,十分优秀!