A
Andrus
I need to display and edit only date part in DataGridView column whose data
source type is DateTime?.
The following code shows and allows to edit also time part.
How to modify this code so that only date is displayed and edited (without
time part) ?
Andrus.
using System;
using System.Windows.Forms;
using System.Collections.Generic;
public class Test {
static void Main() {
Application.Run(new Form1());
}}
class Form1 : Form {
public Form1() {
Controls.Add(new Grid()); }
}
class Grid : DataGridView {
public Grid() {
AutoGenerateColumns = false;
List<cust> l = new List<cust>();
l.Add(new cust());
DataGridViewTextBoxColumn tb = new DataGridViewTextBoxColumn();
tb.DataPropertyName = "c1";
Columns.Add(tb);
DataSource = l;
}
}
class cust {
public DateTime? c1 { get; set; }
public cust() {
c1 = DateTime.Now;
} }
source type is DateTime?.
The following code shows and allows to edit also time part.
How to modify this code so that only date is displayed and edited (without
time part) ?
Andrus.
using System;
using System.Windows.Forms;
using System.Collections.Generic;
public class Test {
static void Main() {
Application.Run(new Form1());
}}
class Form1 : Form {
public Form1() {
Controls.Add(new Grid()); }
}
class Grid : DataGridView {
public Grid() {
AutoGenerateColumns = false;
List<cust> l = new List<cust>();
l.Add(new cust());
DataGridViewTextBoxColumn tb = new DataGridViewTextBoxColumn();
tb.DataPropertyName = "c1";
Columns.Add(tb);
DataSource = l;
}
}
class cust {
public DateTime? c1 { get; set; }
public cust() {
c1 = DateTime.Now;
} }