Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I want to make Cell as readonly

38 views
Skip to first unread message

paritosh upmanyu via .NET 247

unread,
Aug 28, 2004, 8:33:45 AM8/28/04
to
I am using Datagrid Control for window based application, I want to make Cell as readonly for particular Rows not for all. if I used GridColumnstyle readonly property then it makes whole column as readonly and events doesnt fires like currentcellchanged or keypress so i cannot do anything on these events.
--------------------------------
From: paritosh upmanyu

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>MAVhROfBvEinTEDWXh+tlw==</Id>

ClayB [Syncfusion]

unread,
Aug 31, 2004, 4:34:32 AM8/31/04
to
Here is code that made cell 2,2 readonly for me. The idea is to subscribe to
the key events in the TextBox control in the DataGridTextBoxColumn.

// in formload
DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = "MyTable";
this.dataGrid1.TableStyles.Add(ts);

this.dataGrid1.DataSource = dt;

DataGridTextBoxColumn tbc = ts.GridColumnStyles[2] as DataGridTextBoxColumn;
tbc.TextBox.KeyPress += new KeyPressEventHandler(TextBox_KeyPress);
tbc.TextBox.KeyDown += new KeyEventHandler(TextBox_KeyDown);


//the handlers
private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if(this.dataGrid1.CurrentRowIndex == 2)
e.Handled = true;
}

private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
if(this.dataGrid1.CurrentRowIndex == 2 && e.KeyCode == Keys.Delete)
e.Handled = true;
}

==============================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

"paritosh upmanyu via .NET 247" <anon...@dotnet247.com> wrote in message
news:%23s4jDtP...@TK2MSFTNGP11.phx.gbl...

0 new messages