We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

set specified column to readonly

Thread ID:

Created:

Updated:

Platform:

Replies:

90351 Sep 27,2009 02:15 AM UTC Sep 29,2009 09:27 AM UTC WPF 4
loading
Tags: GridControl
luo kun
Asked On September 27, 2009 02:15 AM UTC

Now I use loop implement set specified column to readonly like follow:
for(int i = 1; i <= grid.Model.RowCount; i++)
{
grid.Model[i, 4].ReadOnly = true;
}
Is there an easier way?

And, although has been set to readonly, click the cell, cell can get focus, how to make the cell cant't be focused when readonly?

luo kun
Replied On September 28, 2009 01:40 AM UTC

In addition, it looks like the same code doesn't work right on Grid Tree Control.

Ganesan K [Syncfusion]
Replied On September 28, 2009 11:45 AM UTC

Hi luokun,

Thanks for using Syncfusion products.

You can use VisibleColumns collection for set the entire column as ReadOnly in GridDataControl

[C#]
this.gridControl.VisibleColumns[colIndex].IsReadOnly = true;

[XAML]


You can listen the Grid_CurrentCellActivating event as below to avoid the ReadOnly cell get focused.

void Grid_CurrentCellActivating(object sender, GridCurrentCellActivatingEventArgs e)
{
if (e.CellRowColumnIndex.ColumnIndex == 2)
{
e.Cancel = true;
}
}

Please download the workaround sample from the below locaion and check it out.
http://www.syncfusion.com/uploads/redirect.aspx?file=GridDataControlSample_c611563c.zip&team=development

You can use Columns collection in GridTreeControl for set the entire column as ReadOnly.

treeGrid.Columns[2].StyleInfo.ReadOnly = true;

Let me know if you need any more details.

Thanks
Ganesan

luo kun
Replied On September 29, 2009 01:34 AM UTC

The code can only be used GridDataControl,Grid Control is no similar way?
And GridTreeControl hasn't Grid_CurrentCellActivating event also.

Clay Burch [Syncfusion]
Replied On September 29, 2009 09:27 AM UTC

In the GridTreeControl, if you do not want a column to ever have a current cell (meaning that it cannot be clicked or tabbed into), you can set the the style.Enabled property to false. (This way, the column would not receive focus.)

treeGrid.Columns[2].StyleInfo.Enabled = false;


To subscribe to currentcell events in the GridTreeControl, use its InternalGrid property (which exposes a GridControl derived class). You should subscribe to such events in the GridTreeControl ModelLoaded event. For example,

treeGrid.ModelLoaded += (s, e) =>
{
treeGrid.InternalGrid.CurrentCellActivating += new GridCurrentCellActivatingEventHandler(InternalGrid_CurrentCellActivating);
};


There are no column properties in a GridControl. To set properties on a column in a GridControl, you would need to handle the QueryCellInfo event, and if e.Cell.ColumnIndex points to a particular column, you would then set the properties you want for that column on the e.Style object (like e.Style.ReadOnly = true, or like e.Style.Enabled = false).

For a GridDataControl, the only column properties are those directly exposed in the VisibleColumn (like ReadOnly mentioned in a previous post in this thread). If you want to directly set other style properties you can use gridDataControl.Model.QueryCellInfo as described in the previous paragraph for GridControl.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;