Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Setting Parameters to a Custom RichTextBox Control Hosted in a DataGridViewColumn

$
0
0

I have a custom control called RichTextBoxMasked which is similar to a MaskedTextBox but different. This control, when dropped on a form, allows me to "mask" the value in the RichTextBox.  The enum values for the control are:

enum Mask { None, DateOnly, PhoneWithArea, IpAddress, SSN, Decimal, Digit, AllCaps, SpellCheck}

Either programmatically or via a dropdown in the property grid, I can restrict the value of the control to one of the above formatted types, or perform spellcheck.

So far, so good, but now I want to do the same thing in a DataGridView.  That is, I want a DataGridViewRichTextBoxMaskedColumn that provides the same function for the content of the cells of the columns. 

So I started with very good sample project that I found at http://www.codeproject.com/Articles/31823/RichTextBox-Cell-in-a-DataGridView

This code allows me to host a RichTextBox in the cells of a DataGridViewColumn easily enough by substituting "RichTextBoxMasked" for every occurrence of "RichTextBox", but I can't determine how to pass a Mask value from my enum to the cell so that the editing control knows what to do with it.

I hesitate to post my code because there is a lot of it.  I hope that viewing the Code Project sample will suffice.  However, I have posted a bit of code below that shows the custom control being added to a panel on a form.  I hope to do something similar to a column in a DataGridView.

RichTextBoxMasked rtbx = new RichTextBoxMasked();
rtbx.Masked = Mask.SpellCheck;
pnlEquipmentDetails.Controls.Add(rtbx);
Will I have to resort to a custom DataGridViewRichTextBoxMaskedCell to replace the DataGridViewTextBoxCell class found in the sample?  If not, then how should I modify the sample code?  If so, then how would I go about doing that?


Rob E.





Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>