473,800 Members | 2,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to customise the DataGridViewCol umn 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 11218
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******** ********@TK2MSF TNGP09.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********@yah oo.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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******** ********@TK2MSF TNGP09.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
DataGridViewCol umn 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******** *****@TK2MSFTNG P10.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********@yah oo.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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******** ********@TK2MSF TNGP09.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 DateTimeTextBox Cell : DataGridViewTex tBoxCell
{

private static Type defaultEditType =
typeof(DateTime TextBoxEditingC ontrol);
private static Type defaultValueTyp e = typeof(System.D ateTime);

public DateTimeTextBox Cell(): base()
{ }

public override void InitializeEditi ngControl(int rowIndex, object
initialFormatte dValue, DataGridViewCel lStyle dataGridViewCel lStyle)
{

base.Initialize EditingControl( rowIndex, initialFormatte dValue,
dataGridViewCel lStyle);
DateTimeTextBox EditingControl datetimeTextBox =
DataGridView.Ed itingControl as DateTimeTextBox EditingControl;
DataGridViewCol umn dateTimeTextBox Column =
this.DataGridVi ew.Columns[this.ColumnInde x];
string initialFormatte dValueStr = initialFormatte dValue as string;
if (dateTimeTextBo xColumn is DataGridViewDat eTimeTextBoxCol umn)
{
datetimeTextBox .FieldType =
(winControl.Tex tBox.enumDataTy pe)this._fieldt ype;
if (initialFormatt edValueStr == null)
datetimeTextBox .Text = string.Empty;
else
datetimeTextBox .Text = initialFormatte dValueStr;
}

}

public override Type EditType
{
get { return typeof(DateTime TextBoxEditingC ontrol); }
}

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

return defaultValueTyp e;
}
}

public override object DefaultNewRowVa lue
{
get{ return ""; }
}

public override object Clone()
{
DateTimeTextBox Cell dataGridViewCel l = base.Clone() as
DateTimeTextBox Cell;
return dataGridViewCel l;
}
}

public class DataGridViewDat eTimeTextBoxCol umn : DataGridViewCol umn
{
public DataGridViewDat eTimeTextBoxCol umn(): base(new
DateTimeTextBox Cell())
{
}

public override DataGridViewCel l CellTemplate
{
get{ return base.CellTempla te; }
set
{
DateTimeTextBox Cell dateTimeTextBox Cell = value as
DateTimeTextBox Cell;
if (value != null && dateTimeTextBox Cell == null)
{
throw new InvalidCastExce ption("Value provided for
CellTemplate must be of type DataGridViewDat eTimeTextBox or derive from
it");
}
base.CellTempla te = value;
}
}

public override object Clone()
{
DataGridViewDat eTimeTextBoxCol umn obj =
(DataGridViewDa teTimeTextBoxCo lumn)base.Clone ();
return obj;
}
}
class DateTimeTextBox EditingControl : DateTimeTextBox ,
IDataGridViewEd itingControl
{
System.Windows. Forms.DataGridV iew dataGridView;
private bool valueChanged = false;
int rowIndex;

public DateTimeTextBox EditingControl( )
{ this.textBox.Le ave += new
System.EventHan dler(this.DateT imeTextBox_Leav e);
}

private void DateTimeTextBox _Leave(object sender, System.EventArg s
e)
{
valueChanged = true;
this.EditingCon trolDataGridVie w.NotifyCurrent CellDirty(true) ;
}

public Cursor EditingPanelCur sor
{
get { return Cursors.IBeam; }
}

public virtual System.Windows. Forms.DataGridV iew
EditingControlD ataGridView
{
get { return dataGridView; }
set { dataGridView = value; }
}

public object EditingControlF ormattedValue
{
get { return this.textBox.Te xt; }
set { this.Text = value.ToString( ); }
}

public object GetEditingContr olFormattedValu e(
DataGridViewDat aErrorContexts context)
{
return EditingControlF ormattedValue;
}

public bool EditingControlW antsInputKey(Ke ys key, bool
dataGridViewWan tsInputKey)
{
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 !dataGridViewWa ntsInputKey;
}
public void PrepareEditingC ontrolForEdit(b ool selectAll)
{
}
public bool RepositionEditi ngControlOnValu eChange
{
get{return false;}
}

public int EditingControlR owIndex
{
get{return rowIndex;}
set{rowIndex = value;}
}

public void ApplyCellStyleT oEditingControl ( DataGridViewCel lStyle
dataGridViewCel lStyle)
{ }
public bool EditingControlV alueChanged
{
get{return valueChanged;}
set{valueChange d = value;}
}
}
// DateTimeTextBox control contain Textbox (for display date string) +
button (for call datetimepicker)
// the DateTimeTextBox DefaultBindingP roperty("DataTe xt")
// the problem is when navigated to new row, the column value show empty /
null, it does not save input into datatable

[System.Componen tModel.DefaultB indingProperty( "DataText")]
public partial class DateTimeTextBox : UserControl
{
.......

[System.Componen tModel.Bindable (true), Browsable(true) ,
Category("Behav ior"), Description("Da te and Time displayed")]
public virtual String DataText
{
get
{
try
return
DateTime.Parse( this.textBox.Te xt).ToString("d d-MMM-yyyy",
Application.Cur rentCulture);
catch
return null;
}

set
{
try
this.textBox.Te xt = string.Format(" {0:dd-MMM-yyyy}",
DateTime.Parse( value ));
catch
this.textBox.Te xt = 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
1327
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
1601
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 column As DataGridViewColumn In EmployeesDataGridView.Columns column.HeaderText = String.Concat("Column ", column.Index.ToString) Next
0
1565
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 data schema may change and need to populate a datagrid with the result. The row data will always consist of one simple string element with multiple attributes -- the number and names of the attributes may change. When the data is read in by the...
0
396
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
1281
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 the column. How to make the column show the usercontrol value ?
0
1375
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 Binding("Columns.Visible",appSettings,"DataGridViewColumn0",true, DataSourceUpdateMode.OnPropertyChanged); dataGridViewHistoria.DataBindings.Add(bin);
1
10663
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 manually handle the OnClick, something else, or is there somewhy to set the edit control? Edit type is called when the cell is clicked so it seems to be doing something.
7
8965
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 is done? -- ----------- Thanks, Steve
1
2503
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? Please let me know. Any help will be gratefully appreciated. Thanks. my code:
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10275
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10033
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.