473,472 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Custom DataGridViewColumn. Doesn't accept some of the chars. Help

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:

public class RichTextBoxColumn : DataGridViewColumn
{
public RichTextBoxColumn() : base(new RichTextBoxCell())
{
}

public override DataGridViewCell CellTemplate
{
get
{
return base.CellTemplate;
}
set
{
// Ensure that the cell used for the template is a
RichtextboxCell.
if (value != null &&
!
value.GetType().IsAssignableFrom(typeof(RichTextBo xCell)))
{
throw new InvalidCastException("Must be a
RichTextBoxCell");
}
base.CellTemplate = value;
}
}
}

public class RichTextBoxCell : DataGridViewTextBoxCell
{
public RichTextBoxCell()
: base()
{
//None
}

public override void InitializeEditingControl(int rowIndex,
object
initialFormattedValue, DataGridViewCellStyle
dataGridViewCellStyle)
{
// Set the value of the editing control to the current cell
value.
base.InitializeEditingControl(rowIndex,
initialFormattedValue,
dataGridViewCellStyle);
RichTextBoxEditingControl ctl = DataGridView.EditingControl as
RichTextBoxEditingControl;
if (this.Value==null)
ctl.Text =string.Empty;
else
ctl.Text = (string)this.Value;
}

public override Type EditType
{
get
{
// Return the type of the editing contol that
RichTextBoxCell uses.
return typeof(RichTextBoxEditingControl);
}
}

public override Type ValueType
{
get
{
// Return the type of the value that RichTextBoxCell
contains.
return typeof(string);
}
}

public override object DefaultNewRowValue
{
get
{
// Use empty string as the default value.
return string.Empty;
}
}
}

class RichTextBoxEditingControl : RichTextBox,
IDataGridViewEditingControl
{
DataGridView dataGridView;
private bool valueChanged = false;
int rowIndex;

public RichTextBoxEditingControl()
{
//None;
}

// Implements the
IDataGridViewEditingControl.EditingControlFormatte dValue
// property.
public object EditingControlFormattedValue
{
get
{
return this.Text;
}
set
{
if (value is string)
{
this.Text = (string)value;
}
}
}

// Implements the
// IDataGridViewEditingControl.GetEditingControlForma ttedValue
method.
public object GetEditingControlFormattedValue(
DataGridViewDataErrorContexts context)
{
return EditingControlFormattedValue;
}

// Implements the
// IDataGridViewEditingControl.ApplyCellStyleToEditin gControl
method.
public void ApplyCellStyleToEditingControl(
DataGridViewCellStyle dataGridViewCellStyle)
{
this.Font = dataGridViewCellStyle.Font;
this.ForeColor = dataGridViewCellStyle.ForeColor;
this.BackColor = dataGridViewCellStyle.BackColor;
}

// Implements the
IDataGridViewEditingControl.EditingControlRowIndex
// property.
public int EditingControlRowIndex
{
get
{
return rowIndex;
}
set
{
rowIndex = value;
}
}

// Implements the
IDataGridViewEditingControl.EditingControlWantsInp utKey
// method.
public bool EditingControlWantsInputKey(
Keys key, bool dataGridViewWantsInputKey)
{

// Let the RTB handle the keys listed.
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;
default:
return false;
}
}

// Implements the
IDataGridViewEditingControl.PrepareEditingControlF orEdit
// method.
public void PrepareEditingControlForEdit(bool selectAll)
{
// No preparation needs to be done.
}

// Implements the IDataGridViewEditingControl
// .RepositionEditingControlOnValueChange property.
public bool RepositionEditingControlOnValueChange
{
get
{
return false;
}
}

// Implements the IDataGridViewEditingControl
// .EditingControlDataGridView property.
public DataGridView EditingControlDataGridView
{
get
{
return dataGridView;
}
set
{
dataGridView = value;
}
}

// Implements the IDataGridViewEditingControl
// .EditingControlValueChanged property.
public bool EditingControlValueChanged
{
get
{
return valueChanged;
}
set
{
valueChanged = value;
}
}

// Implements the IDataGridViewEditingControl
// .EditingPanelCursor property.
public Cursor EditingPanelCursor
{
get
{
return base.Cursor;
}
}

protected override void OnTextChanged(EventArgs eventargs)
{
// Notify the DataGridView that the contents of the cell
// have changed.
valueChanged = true;
this.EditingControlDataGridView.NotifyCurrentCellD irty(true);
base.OnTextChanged(eventargs);
}
}
here is how i add the column to my gridview:

RichTextBoxColumn rtbcol = new RichTextBoxColumn();
rtbcol.HeaderText = "my_caption";
rtbcol.DataPropertyName = "my_field"
rtbcol.Width = 250;
rtbcol.ReadOnly = true;
rtbcol.DefaultCellStyle.Alignment =
DataGridViewContentAlignment.TopLeft;
GrdTestSteps.Columns.Add(rtbcol);

Jul 23 '07 #1
1 2484
All, please help. Any hint will be appreciated.

thanks!

Jul 24 '07 #2

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

Similar topics

4
by: Scott C. Reynolds | last post by:
Hi. I have created a templated control, and I want to know how i can set it up so that the projects consuming it will have all the same intellisense benefits of using any other server control. ...
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: Sky Sigal | last post by:
(PS: Cross post from microsoft.pulic.dotnet.framework.aspnet.webcontrols) I've been looking lately for a way to keep the Properties panel for Controls 'clean'... My goal is to keep similar...
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...
2
by: Andy | last post by:
Hi all, I'm creating my own DataGridViewColumn class, and have added a string property to it which should be settable via the Property designer. I've gotten the property to show up, but even if...
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...
0
by: Franz | last post by:
I created a custom dataGridViewColumn which only accept numbers. For this Column, I can define a precision (number of decimal). I can set this property into my code, but not in design mode! ...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
1
by: Charles Bazi | last post by:
Hi, Based on MSDN http://msdn2.microsoft.com/en-us/library/7tas5c80.aspx smple, I have made my custom DataGridViewColumn. I use it to host a custom control, sort of ComboBox, but instead of...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.