Membuat Columntype DatetimePicker Di DatagridView C#

Pada dasarnya Datagridview di C# tidak menyediakan data columntype berjenis datetimepicker. maka dari itu pada artikel kali ini saya akan memberikan tutorial CARA MEMBUAT COLUMNTYPE DATETIMPICKER PADA DATAGRIDVIEW DI CSHARP C#.
Berikut Contoh Coding yang saya gunakan :

=====================================================================
//Public
DateTimePicker dtpEXPRD;

//Event "CellBeginEdit" di datagridview
try
{
if ((dgListBrgSJ.Focused) && (dgListBrgSJ.CurrentCell.ColumnIndex == 8))
{
dtpEXPRD.Location = dgListBrgSJ.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Location;
dtpEXPRD.Visible = true;
dtpEXPRD.Value = DateTime.Today;
}
else
{
dtpEXPRD.Visible = false;
}
}
catch
{
//Exception Disini
}

//Event "CellEndEdit" di datagridview
DateTimeFormatInfo fmtTgl = new DateTimeFormatInfo();
fmtTgl.ShortDatePattern = "yyyy-MM-dd";
try
{
if ((dgListBrgSJ.Focused) && (dgListBrgSJ.CurrentCell.ColumnIndex == 8))
{
dgListBrgSJ.CurrentCell.Value = dtpEXPRD.Value.Date.ToString("d", fmtTgl);
}
}
catch
{
//Exception Di sini
}

//Event "CellClick" di datagridview
try
{
if ((dgListBrgSJ.Focused) && (dgListBrgSJ.CurrentCell.ColumnIndex == 8))
{
dtpEXPRD = new DateTimePicker();
dtpEXPRD.Format = DateTimePickerFormat.Short;
dtpEXPRD.Visible = false;
dtpEXPRD.Width = 100;
dgListBrgSJ.Controls.Add(dtpEXPRD);
dgListBrgSJ.CellBeginEdit += this.dgListBrgSJ_CellBeginEdit;
dgListBrgSJ.CellEndEdit += this.dgListBrgSJ_CellEndEdit;
}
}
catch
{
//Exception di sini
}

//Event "SelectionChanged" Di datagridview
dgListBrgSJ.Controls.Remove(dtpEXPRD);

=====================================================
*Note :
- Sesuaikan Column index sesuai dengan column index datagrid yang anda gunakan.
- "dgListBrgSJ" adalah nama datagridview yang saya gunakan.

=====================================================

Oke demikianlah tutorial dan dokumentasi buat diri saya sendiri juga tentang MEMBUAT FORMAT TANGGAL DI DATAGRIDVIEW C# OR MEMBUAT COLUMNTYPE DATETIMPICKER PADA DATAGRIDVIEW DI CSHARP C# :)
DateTimePicker di datagridview C# [danangweb]


Share on Google Plus
    Blogger Comment
    Facebook Comment

0 komentar:

Post a Comment