我在 C# Winform 项目中有一个 datagridview。此 datagridview 用于将值插入到数据库中。每列最多匹配相应的 db 列。
其中一列是 DateTime 列。我想“验证”这个日期以确保它的格式正确。理想情况下,您会离开单元格,它会将其转换为我选择的日期时间格式。
我使用了一系列事件来尝试创建此功能,但一直遇到问题。我一直遇到的问题是,当事件触发时,该值尚未存储在单元格中。因此,当我做这样的事情时,例如:
private void Grid_Modify_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
if (Grid_Modify.Columns[e.ColumnIndex].Name == "DateTime")
{
Grid_Modify[e.ColumnIndex, e.RowIndex].Value =
Convert.ToDateTime(Grid_Modify[e.ColumnIndex, e.RowIndex].Value).ToString("YYYY-MM-DD hh:mm:ss");
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,它转换为日期时间的值是原始单元格值——而不是我刚刚输入的新值。我认为这是因为在更新单元格值之前触发了事件。
问题是:当我更改日期的值时,格式化日期的最佳方式是什么?
我尝试过的其他事件是:CellLeave、CellValueChanged、CellValidated 和 CellEndEdit。
注意: CellValueChanged 事件是唯一可以实际获取新单元格值的事件,但是,当我更改事件处理程序中的值时,它会陷入无限循环。
点击时我有一次闪光潜水.如果多次按下该按钮,它将一直闪烁,直到执行了点击计数.我想这样,如果用户多次点击该按钮,它将在最后一次点击后停止闪烁.
示例https://jsfiddle.net/va6njdry/
$('button').click(function () {
$('div').fadeOut().fadeIn().fadeOut().fadeIn();
});
Run Code Online (Sandbox Code Playgroud) 我已经实现了这个框架代码,用于执行不同的操作,具体取决于您单击的鼠标按钮以及按钮上的单击次数.
Button button = new Button("Action!");
button.setOnMouseClicked(new EventHandler<MouseEvent>(){
@Override
public void handle(MouseEvent event){
if(event.getButton().equals(MouseButton.PRIMARY)){
if(event.getClickCount() == 2){
System.out.println("Double click");
}else if(event.getClickCount() == 1){
System.out.println("Single click");
}else{
System.out.println("SUPER click");
}
}else{
System.out.println("Secondary click");
}
}
});
Run Code Online (Sandbox Code Playgroud)
我想捕获一个键(例如Ctrl)+鼠标单击事件,因此如果用户在按下键时单击该按钮,我可以捕获鼠标事件处理程序内的键事件,以便扩展可能的操作.我怎么能这样做?
当我使用此代码时,它将我的$ .post()绑定到一个表单,并阻止页面重新加载以提交它:
$("#analyze_audio").submit(function (e) {
debugger;
e.preventDefault();
var url = "/analyze_audio";
var dataToSend = {"analyze_audio": "analyze_audio"};
var callback = function (data) {
debugger;
document.getElementById("audioresponse").innerHTML = (data);
};
$.post(url, dataToSend, callback, 'html');
});
Run Code Online (Sandbox Code Playgroud)
但它不会触发我在其中使用的调试器,因此它不会正确地将事件绑定到我的函数.但是,当我使用这个代码片段时,它完美无缺:
$(function() {
$("#analyze_audio").submit(function (e) {
debugger;
e.preventDefault();
var url = "/analyze_audio";
var dataToSend = {"analyze_audio": "analyze_audio"};
var callback = function (data) {
debugger;
document.getElementById("audioresponse").innerHTML = (data);
};
$.post(url, dataToSend, callback, 'html');
});
});
Run Code Online (Sandbox Code Playgroud)
我真的不明白为什么?
我在类中有以下代码来设置串行端口甚至处理程序.
我得到两个警告; CA1034(不要窝类型),它告诉我,使我delgate私人(这将阻止我是来设置,甚至处理在继承的类),以及CA1009(申报事件的第二个参数作为一个EventArgs,或一个实例一个扩展EventArgs的类型,名为'e'),我不明白.
我的代码如下
myPort.DataReceived += new SerialDataReceivedEventHandler(port_OnDataRecived); //Setup when port is opened
private void port_OnDataRecived(object sender, SerialDataReceivedEventArgs e)
{
int lengthToRead = myPort.BytesToRead;
byte[] rxBytes = new byte[lengthToRead];
myPort.Read(rxBytes, 0, lengthToRead);
PacketReceived(rxBytes, e);
}
public delegate void PacketReceivedEventHandler(object sender, byte[] packet);
public event PacketReceivedEventHandler OnPacketReceived;
public virtual void PacketReceived(byte[] packet, EventArgs e)
{
if (OnPacketReceived != null)
{
OnPacketReceived(this, packet);
}
}
Run Code Online (Sandbox Code Playgroud)
我一直在查看MSDN文章和一些SO问题,但我无法将建议的修复程序与我自己的代码联系起来. 这个答案是有道理的,但转换我的代码看起来像它导致
OnPacketReceived(this, packet);
Run Code Online (Sandbox Code Playgroud)
被替换为
handle(this, new PacketReceivedEventHandler();
Run Code Online (Sandbox Code Playgroud)
这是一个争论(void (object, byte[]) target)(这是我被困的地方).至于尝试修复CA1034警告,我甚至看不到我写的是嵌套类型,MSDN文章没有包含如何修复规则违规的示例.
我是android的新手,尝试运行下面的应用程序.包theoiziruam.clicker.只有btnClick的Onclick事件正在运行,而没有机会使用btnReset将textfield设置为0.我在编译时没有错误,不知道...非常好奇,知道问题是什么.你能帮助我吗?
package theoiziruam.clicker;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
Button btnClick;
Button btnReset;
TextView txtCount;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnClick=(Button)findViewById(R.id.buttonClick);
btnReset=(Button)findViewById(R.id.buttonClick);
txtCount=(TextView) findViewById(R.id.textViewCount);
btnReset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtCount.setText(String.valueOf(0));
}
});
btnClick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String countValue=txtCount.getText().toString();
int intCountValue= Integer.parseInt(countValue);
intCountValue++;
txtCount.setText(String.valueOf(intCountValue));
if (intCountValue>10) { }
}
});
}
Run Code Online (Sandbox Code Playgroud) 我希望在Excel中运行VBA脚本,并在某个时刻暂停,直到特定工作簿打开.然后继续原始工作簿中的脚本.这是因为原始工作簿需要从新打开的工作簿导入数据,然后关闭该新工作簿.我假设我应该使用某种Windows事件处理程序来监视文件打开等事情.
正在使用的版本是MS windows 10和excel 2013
So I know that we can have multiple event handlers on the .on() method
$(document).on({
'click': function (e) {
// function
},
'hover': function (e) {
// function
}
});
Run Code Online (Sandbox Code Playgroud)
but is there anyway we can add multiple selectors to each event handler?
like this:
$(document).on('click', '#foo, .foo', function () {
// function
});
Run Code Online (Sandbox Code Playgroud)
but with multiple .on() methods:
$(document).on({
'click', '#foo': function (e) {
// doesn't work :(
},
'hover', '.foo': function (e) {
// doesn't work :(
} …Run Code Online (Sandbox Code Playgroud) 目前我所做的是检查页面中是否存在元素.但是我的代码有很多条件,因为那样.当元素不存在时,Jquery事件侦听器不会显示错误.jquery如何处理这个以及我可以使用哪些texniques进行更好的设计?
var el = document.getElementById('el');
var another_el = document.getElementById('another_el');
if(another_el){
el.addEventListener('click', swapper, false);
}
if(el){
el.addEventListener('click', swapper, false);
}
....
...
Run Code Online (Sandbox Code Playgroud) 我了解到,使用onclickHTML被认为是不好的做法。现在,我正在阅读一个React教程。本教程使用<button onClick={shoot}>Take the Shot!</button>。在React中这也被认为是不好的做法吗?如果是,那么“正确”的方法是什么?
event-handling ×10
javascript ×4
jquery ×4
events ×3
c# ×2
android ×1
animation ×1
datagridview ×1
excel ×1
excel-vba ×1
java ×1
javafx ×1
reactjs ×1
vba ×1
winforms ×1