Click here to Skip to main content
16,006,493 members
Home / Discussions / C#
   

C#

 
GeneralRe: How can I find out which key was pressed Pin
Mridang Agarwalla15-Aug-05 23:07
Mridang Agarwalla15-Aug-05 23:07 
AnswerRe: How can I find out which key was pressed Pin
Hadi Fakhreddine15-Aug-05 20:39
Hadi Fakhreddine15-Aug-05 20:39 
AnswerRe: How can I find out which key was pressed Pin
snouto15-Aug-05 22:17
snouto15-Aug-05 22:17 
GeneralDataGrid Pin
econner15-Aug-05 19:04
econner15-Aug-05 19:04 
GeneralRe: DataGrid Pin
Alomgir Miah16-Aug-05 3:54
Alomgir Miah16-Aug-05 3:54 
GeneralDesigner problem Pin
Kerby15-Aug-05 18:34
Kerby15-Aug-05 18:34 
GeneralDateTimePicker in Datagrid Pin
deep715-Aug-05 17:57
deep715-Aug-05 17:57 
GeneralRe: DateTimePicker in Datagrid Pin
Alomgir Miah16-Aug-05 3:43
Alomgir Miah16-Aug-05 3:43 
using System;
using System.Data;
using System.Windows.Forms;
using System.Drawing;

namespace Test.Controls
{
///
/// Summary description for DataGridTimePickerColumn.
/// This class builds the DateTimePicker column user control for datagrids for windows application.
/// It inherits DataGridTextBoxColumn, since this is already an available control in the .Net Framework.
/// What needs to be modified, depending on the application, is the ValueChanged event.
/// To use this class, simply add it to the project, construct an instance, and use its properties.
/// this is a sample usage:
///
/// DataGridTimePickerColumn col3=new DataGridTimePickerColumn();
/// dataGrid1.TableStyles[0].GridColumnStyles.Add(col3);
/// dataGrid1.TableStyles[0].GridColumnStyles[7].MappingName="Date Time";
/// dataGrid1.TableStyles[0].GridColumnStyles[7].HeaderText="Date Time";
/// dataGrid1.TableStyles[0].GridColumnStyles[7].Width=100;
///
///

public class DataGridTimePickerColumn : DataGridTextBoxColumn//DataGridColumnStyle
{
private DateTimePicker myDateTimePicker = new DateTimePicker();
// The isEditing field tracks whether or not the user is
// editing data with the hosted control.
private bool isEditing;

public DataGridTimePickerColumn() : base()
{
myDateTimePicker.Visible = false;
}

protected override void Abort(int rowNum)
{
isEditing = false;
myDateTimePicker.ValueChanged -=
new EventHandler(TimePickerValueChanged);
Invalidate();
}

protected override bool Commit
(CurrencyManager dataSource, int rowNum)
{
myDateTimePicker.Bounds = Rectangle.Empty;

myDateTimePicker.ValueChanged -=
new EventHandler(TimePickerValueChanged);

if (!isEditing)
return true;

isEditing = false;

try
{
DateTime value = myDateTimePicker.Value;
SetColumnValueAtRow(dataSource, rowNum, value);
}
catch (Exception)
{
Abort(rowNum);
return false;
}

Invalidate();
return true;
}

protected override void Edit(
CurrencyManager source,
int rowNum,
Rectangle bounds,
bool readOnly,
string instantText,
bool cellIsVisible)
{
DateTime value = DateTime.Parse(GetColumnValueAtRow(source, rowNum).ToString());
if (cellIsVisible)
{
myDateTimePicker.Bounds = new Rectangle
(bounds.X + 2, bounds.Y + 2,
bounds.Width - 4, bounds.Height - 4);
myDateTimePicker.Value = value;
myDateTimePicker.Visible = true;
myDateTimePicker.ValueChanged +=
new EventHandler(TimePickerValueChanged);
}
else
{
myDateTimePicker.Value = value;
myDateTimePicker.Visible = false;
}

if (myDateTimePicker.Visible)
DataGridTableStyle.DataGrid.Invalidate(bounds);
}

protected override Size GetPreferredSize(
Graphics g,
object value)
{
return new Size(100, myDateTimePicker.PreferredHeight + 4);
}

protected override int GetMinimumHeight()
{
return myDateTimePicker.PreferredHeight + 4;
}

protected override int GetPreferredHeight(Graphics g,
object value)
{
return myDateTimePicker.PreferredHeight + 4;
}

protected override void Paint(Graphics g,
Rectangle bounds,
CurrencyManager source,
int rowNum)
{
Paint(g, bounds, source, rowNum, false);
}
protected override void Paint(
Graphics g,
Rectangle bounds,
CurrencyManager source,
int rowNum,
bool alignToRight)
{
Paint(
g,bounds,
source,
rowNum,
Brushes.Red,
Brushes.Blue,
alignToRight);
}
protected override void Paint(
Graphics g,
Rectangle bounds,
CurrencyManager source,
int rowNum,
Brush backBrush,
Brush foreBrush,
bool alignToRight)
{
DateTime date = DateTime.Parse(GetColumnValueAtRow(source, rowNum).ToString());
Rectangle rect = bounds;
g.FillRectangle(backBrush,rect);
rect.Offset(0, 2);
rect.Height -= 2;
g.DrawString(date.ToString("d"),
this.DataGridTableStyle.DataGrid.Font,
foreBrush, rect);
}

protected override void SetDataGridInColumn(DataGrid value)
{
base.SetDataGridInColumn(value);
if (myDateTimePicker.Parent != null)
{
myDateTimePicker.Parent.Controls.Remove
(myDateTimePicker);
}
if (value != null)
{
value.Controls.Add(myDateTimePicker);
}
}

private void TimePickerValueChanged(object sender, EventArgs e)
{
this.isEditing = true;
base.ColumnStartedEditing(myDateTimePicker);
}
}
}


Live Life King Size
Alomgir Miah
GeneralRe: DateTimePicker in Datagrid Pin
deep716-Aug-05 20:52
deep716-Aug-05 20:52 
GeneralRe: DateTimePicker in Datagrid Pin
Alomgir Miah17-Aug-05 5:39
Alomgir Miah17-Aug-05 5:39 
Generalstil having csc.exe problems Pin
Heinz_15-Aug-05 17:49
Heinz_15-Aug-05 17:49 
GeneralRe: stil having csc.exe problems Pin
Vasudevan Deepak Kumar15-Aug-05 18:55
Vasudevan Deepak Kumar15-Aug-05 18:55 
GeneralRe: stil having csc.exe problems Pin
Guffa15-Aug-05 18:57
Guffa15-Aug-05 18:57 
Generalruntime compile problem Pin
sduhd15-Aug-05 16:36
sduhd15-Aug-05 16:36 
QuestionDo timers run out ? Pin
Christian Graus15-Aug-05 15:38
protectorChristian Graus15-Aug-05 15:38 
AnswerRe: Do timers run out ? Pin
S. Senthil Kumar15-Aug-05 23:49
S. Senthil Kumar15-Aug-05 23:49 
GeneralRe: Do timers run out ? Pin
Christian Graus16-Aug-05 13:21
protectorChristian Graus16-Aug-05 13:21 
GeneralRe: Do timers run out ? Pin
Robert M Greene16-Aug-05 15:05
Robert M Greene16-Aug-05 15:05 
GeneralRe: Do timers run out ? Pin
Christian Graus16-Aug-05 15:18
protectorChristian Graus16-Aug-05 15:18 
GeneralRe: Do timers run out ? Pin
Robert M Greene16-Aug-05 15:25
Robert M Greene16-Aug-05 15:25 
GeneralRe: Do timers run out ? Pin
Christian Graus16-Aug-05 15:29
protectorChristian Graus16-Aug-05 15:29 
GeneralRe: Do timers run out ? Pin
S. Senthil Kumar16-Aug-05 19:41
S. Senthil Kumar16-Aug-05 19:41 
GeneralRe: Do timers run out ? Pin
Christian Graus16-Aug-05 19:44
protectorChristian Graus16-Aug-05 19:44 
GeneralRe: Do timers run out ? Pin
S. Senthil Kumar17-Aug-05 1:01
S. Senthil Kumar17-Aug-05 1:01 
GeneralRe: Do timers run out ? Pin
Christian Graus17-Aug-05 11:43
protectorChristian Graus17-Aug-05 11:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.