Click here to Skip to main content
15,896,437 members
Home / Discussions / C#
   

C#

 
GeneralClass parser in C# Pin
thedex29-Aug-03 4:22
thedex29-Aug-03 4:22 
GeneralRe: Class parser in C# Pin
Frank Olorin Rizzi29-Aug-03 7:37
Frank Olorin Rizzi29-Aug-03 7:37 
GeneralRe: Class parser in C# Pin
leppie29-Aug-03 7:49
leppie29-Aug-03 7:49 
GeneralRe: Class parser in C# Pin
Frank Olorin Rizzi29-Aug-03 8:20
Frank Olorin Rizzi29-Aug-03 8:20 
GeneralRe: Class parser in C# Pin
leppie29-Aug-03 9:05
leppie29-Aug-03 9:05 
GeneralRe: Class parser in C# Pin
Frank Olorin Rizzi29-Aug-03 11:28
Frank Olorin Rizzi29-Aug-03 11:28 
GeneralRe: Class parser in C# Pin
leppie29-Aug-03 13:40
leppie29-Aug-03 13:40 
Generaldatagrid Pin
Member 52474029-Aug-03 1:26
Member 52474029-Aug-03 1:26 
hi,

i have set the DataGridColumnStyle in my datagrid of DateTimePicker control...but the problem is i unable to preserve data in cell....when i change the focus from the cell....pls tell me what should i do? code is given below...

-bhavin



using System;
using System.Data;
using System.Windows.Forms;
using System.Drawing;

// This example shows how to create your own column style that
// hosts a control, in this case, a DateTimePicker.
public class DataGridTimePickerColumn : 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;
myDateTimePicker.Dock=DockStyle.Fill;
}

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)
GetColumnValueAtRow(source, rowNum);
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)
GetColumnValueAtRow(source, rowNum);
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);
}
}



GeneralFind the greatest and the smallest Pin
laphijia28-Aug-03 22:34
laphijia28-Aug-03 22:34 
GeneralRe: Find the greatest and the smallest Pin
Paul Ingles29-Aug-03 0:14
Paul Ingles29-Aug-03 0:14 
GeneralSimple question: StreamWriter Pin
devvvy28-Aug-03 21:52
devvvy28-Aug-03 21:52 
GeneralRe: Simple question: StreamWriter Pin
Daniel Turini29-Aug-03 8:00
Daniel Turini29-Aug-03 8:00 
GeneralRe: Simple question: StreamWriter Pin
Tatham30-Aug-03 19:03
Tatham30-Aug-03 19:03 
QuestionInt* into IntPtr? Pin
novachen28-Aug-03 19:18
novachen28-Aug-03 19:18 
AnswerRe: Int* into IntPtr? Pin
MaxVC29-Aug-03 4:40
MaxVC29-Aug-03 4:40 
AnswerRe: Int* into IntPtr? Pin
leppie29-Aug-03 7:19
leppie29-Aug-03 7:19 
GeneralArrayList capacity Pin
Meysam Mahfouzi28-Aug-03 17:23
Meysam Mahfouzi28-Aug-03 17:23 
GeneralRe: ArrayList capacity Pin
Frank Olorin Rizzi28-Aug-03 18:28
Frank Olorin Rizzi28-Aug-03 18:28 
GeneralRe: ArrayList capacity Pin
Holger Persch28-Aug-03 23:32
Holger Persch28-Aug-03 23:32 
GeneralRe: ArrayList capacity Pin
Philip Fitzsimons29-Aug-03 3:45
Philip Fitzsimons29-Aug-03 3:45 
GeneralRe: ArrayList capacity Pin
David Stone29-Aug-03 6:50
sitebuilderDavid Stone29-Aug-03 6:50 
GeneralRe: ArrayList capacity Pin
Philip Fitzsimons29-Aug-03 6:53
Philip Fitzsimons29-Aug-03 6:53 
GeneralRe: ArrayList capacity Pin
leppie29-Aug-03 7:39
leppie29-Aug-03 7:39 
GeneralRe: ArrayList capacity Pin
David Stone29-Aug-03 10:23
sitebuilderDavid Stone29-Aug-03 10:23 
GeneralRe: ArrayList capacity Pin
Philip Fitzsimons30-Aug-03 3:29
Philip Fitzsimons30-Aug-03 3:29 

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.