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

Home Posts Topics Members FAQ

Disabled DataGridView Textbox column

Hi,

I am having difficulties creating a derived class for
DisabledDataGridViewTextBoxColumn and cell when the VisualStyle is not
supported. Basically I am down to either using ControlPaint or Graphics
to achieve this. But with Graphics, I am not sure how I can make them
diabled.

Below are my codes:

class DataGridViewDisabledTextBoxColumn : DataGridViewTextBoxColumn
{
public DataGridViewDisabledTextBoxColumn() {
this.CellTemplate = new DataGridViewDisabledTextBoxCell();

}
}
public class DataGridViewDisabledTextBoxCell :
DataGridViewTextBoxCell {
private bool enabledValue;
public bool Enabled {
get {
return enabledValue;
}
set {
enabledValue = value;
}
}

// Override the Clone method so that the Enabled property is
copied.
public override object Clone() {
DataGridViewDisabledTextBoxCell cell =
(DataGridViewDisabledTextBoxCell)base.Clone();
cell.Enabled = this.Enabled;
return cell;
}

// By default, enable the textbox cell.
public DataGridViewDisabledTextBoxCell() {
this.enabledValue = true;
}

protected override void Paint(Graphics graphics,
Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
DataGridViewElementStates elementState, object value,
object formattedValue, string errorText,
DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts) {
// The button cell is disabled, so paint the border,
// background, and disabled button for the cell.
if (!this.enabledValue) {
// Draw the cell background, if specified.
if ((paintParts & DataGridViewPaintParts.Background) ==
DataGridViewPaintParts.Background) {
SolidBrush cellBackground =
new SolidBrush(cellStyle.BackColor);
graphics.FillRectangle(cellBackground, cellBounds);
cellBackground.Dispose();
}

// Draw the cell borders, if specified.
if ((paintParts & DataGridViewPaintParts.Border) ==
DataGridViewPaintParts.Border) {
PaintBorder(graphics, clipBounds, cellBounds,
cellStyle,
advancedBorderStyle);
}

// Calculate the area in which to draw the textbox.
Rectangle textBoxArea = cellBounds;
Rectangle textBoxAdjustment =
this.BorderWidths(advancedBorderStyle);
textBoxArea.X += textBoxAdjustment.X;
textBoxArea.Y += textBoxAdjustment.Y;
textBoxArea.Height -= textBoxAdjustment.Height;
textBoxArea.Width -= textBoxAdjustment.Width;

// Draw the disabled textbox

if
(System.Windows.Forms.VisualStyles.VisualStyleRend erer.IsSupported &&
Application.RenderWithVisualStyles) {
if
(System.Windows.Forms.VisualStyles.VisualStyleRend erer.IsElementDefined(System.Windows.Forms.VisualS tyles.VisualStyleElement.Button.PushButton.Normal) )
{
TextBoxRenderer.DrawTextBox(graphics,
textBoxArea, System.Windows.Forms.VisualStyles.TextBoxState.Dis abled);

// Draw the disabled text.
if (this.FormattedValue is String) {
TextRenderer.DrawText(graphics,
(string)this.FormattedValue,
this.DataGridView.Font,
textBoxArea, SystemColors.GrayText);
}
}
} else {
Brush brsh = new SolidBrush(Color.Gray);
Brush brFill = new SolidBrush(Color.LightGray);
Pen p = new Pen(brsh,1);
graphics.DrawRectangle(p, textBoxArea);
graphics.FillRectangle(brFill, textBoxArea);
graphics.DrawString((string)this.FormattedValue,
this.DataGridView.Font, brsh, textBoxArea);
}
} else {
base.Paint(graphics, clipBounds, cellBounds,
rowIndex,
elementState, value, formattedValue, errorText,
cellStyle, advancedBorderStyle, paintParts);
}
}
}

I would appreciate if anyone can point me out here.

Thanks,
Sunny

May 8 '06 #1
0 2465

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

Similar topics

0
by: Vish | last post by:
Hi all, I am using VS 2005 Beta2. I have a DataGridView with 1 textbox column and 1 comboboxcolumn. When user changes the selected value in the DataGridView combobox column, i would like to...
3
by: Bob | last post by:
Thinking two things, 1- Creating a userControl -yeah you guessed it, a multi column drop down combobox - I've looked at several articles and did not find what I need, one that's bindable and that...
6
by: Satya | last post by:
Hi, I am using a DataGridView to display a large amount of data and so need to use filters for displaying certain data. For this I want to provide a textbox for each column of the DataGridView so...
7
by: Ryan | last post by:
I have a DataGridView which displays numeric (Int32) data from an underlying database. I want the numbers to be displayed in numeric format "#,###" (with commas). I want to also limit the user so...
2
by: David Jackson | last post by:
Hello, I have a DataGridView which is populated from an Access database. The final column is a calculated column. I have set this to ReadOnly in the column collection properties, but now I would...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
12
by: cj | last post by:
When viewing a datatable in a datagridview one of the columns in it is a "note" field which can be quite long. I would like to have the note field of the currently selected row of the datagrid...
9
by: Miro | last post by:
My current headache is proper is with the datagridview I am starting to realize that a DataGridView within vs2008 is not as 'robust' as a 'textboxfield' by default for example. Example: A...
1
by: JB | last post by:
Hi All, I'd like to display password characters in a DataGridView column, the same way I can do in a standard TextBox by using the PasswordChar property (i.e.typed characters replaced by a star...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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: 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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.