473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to customise the DataGridViewColumn with a UserContro editingcontrol ?

I do a customise DataGridColumn with a UserControl (TextBox + Button for
Calender), DataGridView does not show the data content of the column.

Mar 25 '06 #1
5 11189
vj
Why do you need a TextBox and a Calendar.. when you can just click to show a
calendar, allow the user to change date then...

VJ

"Tsair" <ls*****@yahoo.com> wrote in message
news:uv****************@TK2MSFTNGP09.phx.gbl...
I do a customise DataGridColumn with a UserControl (TextBox + Button for
Calender), DataGridView does not show the data content of the column.

Mar 25 '06 #2
the existing DateTimePicker input by Day then Month then Year which is not
convineance in keyboard stroke.

I customise the usercontrol with textbox + button to just type in the day
month year, and the button provide the option for popup the Datetimepicker
for selection.

When i include this usercontrol into DataGridView column, the column does
not show the input as user key in, it just blank.
"vj" <vi********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Why do you need a TextBox and a Calendar.. when you can just click to show
a calendar, allow the user to change date then...

VJ

"Tsair" <ls*****@yahoo.com> wrote in message
news:uv****************@TK2MSFTNGP09.phx.gbl...
I do a customise DataGridColumn with a UserControl (TextBox + Button for
Calender), DataGridView does not show the data content of the column.


Mar 28 '06 #3
Check out the following MSDN2 article. It illustrates a custom
DataGridViewColumn control that uses a DateTimePicker:

http://msdn2.microsoft.com/en-us/lib...80(VS.80).aspx

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"Tsair" <ls*****@yahoo.com> wrote in message
news:OW*************@TK2MSFTNGP10.phx.gbl...
the existing DateTimePicker input by Day then Month then Year which is not
convineance in keyboard stroke.

I customise the usercontrol with textbox + button to just type in the day
month year, and the button provide the option for popup the Datetimepicker
for selection.

When i include this usercontrol into DataGridView column, the column does
not show the input as user key in, it just blank.
"vj" <vi********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Why do you need a TextBox and a Calendar.. when you can just click to
show a calendar, allow the user to change date then...

VJ

"Tsair" <ls*****@yahoo.com> wrote in message
news:uv****************@TK2MSFTNGP09.phx.gbl...
I do a customise DataGridColumn with a UserControl (TextBox + Button for
Calender), DataGridView does not show the data content of the column.



Mar 28 '06 #4
My Code like this

public class DateTimeTextBoxCell : DataGridViewTextBoxCell
{

private static Type defaultEditType =
typeof(DateTimeTextBoxEditingControl);
private static Type defaultValueType = typeof(System.DateTime);

public DateTimeTextBoxCell(): base()
{ }

public override void InitializeEditingControl(int rowIndex, object
initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{

base.InitializeEditingControl(rowIndex, initialFormattedValue,
dataGridViewCellStyle);
DateTimeTextBoxEditingControl datetimeTextBox =
DataGridView.EditingControl as DateTimeTextBoxEditingControl;
DataGridViewColumn dateTimeTextBoxColumn =
this.DataGridView.Columns[this.ColumnIndex];
string initialFormattedValueStr = initialFormattedValue as string;
if (dateTimeTextBoxColumn is DataGridViewDateTimeTextBoxColumn)
{
datetimeTextBox.FieldType =
(winControl.TextBox.enumDataType)this._fieldtype;
if (initialFormattedValueStr == null)
datetimeTextBox.Text = string.Empty;
else
datetimeTextBox.Text = initialFormattedValueStr;
}

}

public override Type EditType
{
get { return typeof(DateTimeTextBoxEditingControl); }
}

public override Type ValueType
{
get
{
Type valueType = base.ValueType;
if (valueType != null)
return valueType;

return defaultValueType;
}
}

public override object DefaultNewRowValue
{
get{ return ""; }
}

public override object Clone()
{
DateTimeTextBoxCell dataGridViewCell = base.Clone() as
DateTimeTextBoxCell;
return dataGridViewCell;
}
}

public class DataGridViewDateTimeTextBoxColumn : DataGridViewColumn
{
public DataGridViewDateTimeTextBoxColumn(): base(new
DateTimeTextBoxCell())
{
}

public override DataGridViewCell CellTemplate
{
get{ return base.CellTemplate; }
set
{
DateTimeTextBoxCell dateTimeTextBoxCell = value as
DateTimeTextBoxCell;
if (value != null && dateTimeTextBoxCell == null)
{
throw new InvalidCastException("Value provided for
CellTemplate must be of type DataGridViewDateTimeTextBox or derive from
it");
}
base.CellTemplate = value;
}
}

public override object Clone()
{
DataGridViewDateTimeTextBoxColumn obj =
(DataGridViewDateTimeTextBoxColumn)base.Clone();
return obj;
}
}
class DateTimeTextBoxEditingControl : DateTimeTextBox,
IDataGridViewEditingControl
{
System.Windows.Forms.DataGridView dataGridView;
private bool valueChanged = false;
int rowIndex;

public DateTimeTextBoxEditingControl()
{ this.textBox.Leave += new
System.EventHandler(this.DateTimeTextBox_Leave);
}

private void DateTimeTextBox_Leave(object sender, System.EventArgs
e)
{
valueChanged = true;
this.EditingControlDataGridView.NotifyCurrentCellD irty(true);
}

public Cursor EditingPanelCursor
{
get { return Cursors.IBeam; }
}

public virtual System.Windows.Forms.DataGridView
EditingControlDataGridView
{
get { return dataGridView; }
set { dataGridView = value; }
}

public object EditingControlFormattedValue
{
get { return this.textBox.Text; }
set { this.Text = value.ToString(); }
}

public object GetEditingControlFormattedValue(
DataGridViewDataErrorContexts context)
{
return EditingControlFormattedValue;
}

public bool EditingControlWantsInputKey(Keys key, bool
dataGridViewWantsInputKey)
{
switch (key & Keys.KeyCode)
{
case Keys.Left:
case Keys.Up:
case Keys.Down:
case Keys.Right:
case Keys.Home:
case Keys.End:
case Keys.PageDown:
case Keys.PageUp:
return true;
}

return !dataGridViewWantsInputKey;
}
public void PrepareEditingControlForEdit(bool selectAll)
{
}
public bool RepositionEditingControlOnValueChange
{
get{return false;}
}

public int EditingControlRowIndex
{
get{return rowIndex;}
set{rowIndex = value;}
}

public void ApplyCellStyleToEditingControl( DataGridViewCellStyle
dataGridViewCellStyle)
{ }
public bool EditingControlValueChanged
{
get{return valueChanged;}
set{valueChanged = value;}
}
}
// DateTimeTextBox control contain Textbox (for display date string) +
button (for call datetimepicker)
// the DateTimeTextBox DefaultBindingProperty("DataText")
// the problem is when navigated to new row, the column value show empty /
null, it does not save input into datatable

[System.ComponentModel.DefaultBindingProperty("Data Text")]
public partial class DateTimeTextBox : UserControl
{
.......

[System.ComponentModel.Bindable(true), Browsable(true),
Category("Behavior"), Description("Date and Time displayed")]
public virtual String DataText
{
get
{
try
return
DateTime.Parse(this.textBox.Text).ToString("dd-MMM-yyyy",
Application.CurrentCulture);
catch
return null;
}

set
{
try
this.textBox.Text = string.Format("{0:dd-MMM-yyyy}",
DateTime.Parse( value ));
catch
this.textBox.Text = value;
}
}
}
Mar 29 '06 #5
Hi,
Have you figure out how to display the editted value of the usercontrol to display in the datagridview cell????

---
Posted via www.DotNetSlackers.com
Apr 5 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: tsair | last post by:
When i add a new property into datagridviewcolumn, the property alway show null even i has been key in something in the property. how to solve this ? thank you
1
by: Werner Boelen | last post by:
After binding a DataGridView to a datasource and looping through the columns to update the headertext, some captions get modified and some don't. Sample code copied from ms-help: For Each...
0
by: c j anderson, mcp | last post by:
Synopsis: DataGridViewColumn reorder does not update display, but a repopulation of underlying dataset does... I must be missing something obvious. I have a scenario where the underlying XML...
0
by: perspolis | last post by:
Hi all I created a customized DataGridViewColumn and added a property named AutoMerge like this private bool autoMerge=false; public bool AutoMerge{ set{this.autoMerge = value;}
0
by: Tsair | last post by:
I create a custom DataGridViewColumn from a usercontrol with Textbox and a button. After input the usercontrol textbox value and press Tab to next column, the value of the textbox does not show in...
0
by: BlueBox | last post by:
hello, is there a way to bind to DataGridViewColumn.Visible property? unfortunately the code below doesn't work Binding bin = new...
1
by: John J. Hughes II | last post by:
I am trying to create a custom DataGridViewCell which is "NOT" derived from DataGridViewTextBoxColumn. The painting works fine but I am unable to get the control into edit mode. Do I need to...
7
by: SteveT | last post by:
I would like to create a customized DataGridViewColumn called DataGridViewCheckedListBoxColumn. I'd like the ability to multi-select items in the list. Does anyone know of an example of how this...
1
by: lbelkova | last post by:
Hello, I've created a custom DataGridViewColumn. Everything work well, except for some reason the column doesn't accept some of the chars: "q", "." and "'". Did anybody have a similar problem?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.