我目前使用:
lable1.Text = DateTime.Now.ToShortDateString();
Run Code Online (Sandbox Code Playgroud)
显示我的短日期时间label1.
因为上面的代码显示了来自windows机器的日期(如果你在Windows程序设置中更改日期,程序中的日期也会改变),这对我没有任何帮助.我需要在label1(GMT + 0日期)和label2(GMT + 0时钟)中显示GMT日期和时间,以便独立于Windows机器时钟设置显示日期和时间.
我没有任何线索如何做到这一点.请记住,我有一个24小时制不是12小时制.
我试图从鼠标单击事件的 datagridview 中获取价值。
在我单击 datagridview 中的标题之前,效果很好。我收到一条错误消息:
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name:index
Run Code Online (Sandbox Code Playgroud)
我使用此代码来检测鼠标点击:
private void dataGridView1_CellMouseClick(Object sender, DataGridViewCellMouseEventArgs e)
{
if (dataGridView1.Rows[e.RowIndex].Index != -1)
{
textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
}
else
{
textBox1.Text = "";
}
}
Run Code Online (Sandbox Code Playgroud)
“dataGridView1.Rows[e.RowIndex].Index != -1”不起作用,我不知道为什么。
任何禁用标题上的鼠标单击事件的简单解决方案都会很棒!谢谢!
我也用:
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
Run Code Online (Sandbox Code Playgroud)
选择整列并且 CellContentClick 不起作用。如果幸运的话,CEllContentClick 的工作效率是 3/10。