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. Image for the cookie policy date
close icon

CellType = "Static"

Hi, I'm populating a the grid with gridcontrol1.Model.PopulateValues(GridRangeInfo.Cells(0, 0, mRowCount, mColumnCount), mDataArray) And then I'm going back and activating/deactivating certain rows and columns by using either .Model.RowStyles(RowIndex).CellType = "TextBox" or .Model.ColStyles(ColumnIndex).CellType = "Static" But I've come to a point where I need even more control over a single cell. Say the row and column in which it resides are set to static, but it needs to be a textbox. Is there anyway to do that? Something like .model.CellStyles(row, col).CellType = "TextBox" Thanks, Tom

13 Replies

AD Administrator Syncfusion Team December 4, 2002 06:43 AM UTC

Tom, You can change the CellType with code like: Me.GridControl1(row,col).CellType = "...." at any point from code PROVIDED you do it while that particular cell is not the current cell. After the change, when the cell becomes current, it will use whatever celltype you set. But, probably a better way to handle this dynamic swapping of cell types is to listen to the QueryCellInfo event. In your handler, check the e.RowIndex and e.ColIndex to decide what celltype this particular cell should be, and then set e.Style.CellType accordingly. Also, if you change the e.Style member, then set the e.Handled property to true.

TL Tom Le Blanc December 9, 2002 08:03 PM UTC

Is there any reason why my Static cells can have a drag & drop operation work on them, while the CellControlsGrid sample doesn't allow it. What did I miss? Thanks, Tom

AD Administrator Syncfusion Team December 9, 2002 08:13 PM UTC

You can turn off the D&D cursor by unchecking the OleDataSource and OleDropTarget flags in the grid's ControllerOptions property.

SW Steve Weixel December 10, 2002 03:29 PM UTC

Clay, Please correct me if I am not understanding something correctly. It seems that if the cells are marked static, they should in fact be completely static and not changeable by any keyboard or mouse actions, including typing, copy&paste, or drag&drop. Now, would your syggestion disable dragging and dropping for the whole grid, or is there a way to do this on a cell level? Or are you (and I surely hope that you are not) suggesting that we keep turning it on or off as the user moves around? While that may work, it places a lot of burden on our side to deal with this, when it seems that it should be dealt with automatically by the grid. - Steve

AD Administrator Syncfusion Team December 10, 2002 03:50 PM UTC

Is the problem that you can see the D&D cursor when your static cell becomes the current cell if you move the mouse to the cell border? If this is the problem, try setting the styles Enabled property to false for that cell. This will make it impossible for the cell to become the current cell, and thus you will not have the problem with the D&D cursor caused by a static cell also being the current cell. If you don't want to be able to copy it or move it, then is there a need for it to become current? In general, the D&D support is a grid wide property. If you need to control it on a cell level, I suspect it will require you handling mouse movements and hittesting.

SW Steve Weixel December 10, 2002 04:20 PM UTC

The problem is not that you can SEE the D&D cursor, but that you can actually drag the static cells; i.e. you can move them around the grid. We have cells that we don't want the user to be able to edit, and we are currently doing this by setting them to static. We previously tried disabling them, but we had to abandon that because we still want the user to be able to select them. I don't understand what the point of static if you don't fully prevent them from being changed. Maybe we are not understanding the purpose of static, in which case we need a mode that is "read only" from the user interface. Basically we want the same behavior as disabling gives us, except we still want to be able to navigate/select the cells with the keyboard. - Steve

AD Administrator Syncfusion Team December 10, 2002 04:44 PM UTC

Steve, setting the cell type for a cell to be "Static" means nothing else than that the editor for this cell is the GridStaticCellRenderer. This renderer just displays text but does not provide any UI/editor for editing the cell contents in-place. All other functions of the grid that are operating on a range of cells are implemented within the grid and they still work no matter what cell-type you specify. What you are looking for is specific behavior for that cell similar to Clickable, Enabled or other properties of a style. Maybe something like "Locked" property so that the cell can't be moved. I'll make a note about this and see if we can such a property in a future version. You can achives similar results for now by processing some of the following events: First, there is a SaveCellInfo event. In that event handler you can check if the cell type equals "Static" and if that is the case set e.Cancel = true so that the cell does not get modified. Another event you might look at is OnQueryOleDataSourceData. There you can check if the selected range of cells contains cells that you do not want to be dragged and set e.Cancel = true to avoid dragging cells. This event also allows you to avoid a Drag-cursor being displayed. Take also a look at CellsChanging. It occurs before the contents of a specified range of cells are being changed and you avoid the operation by setting e.Cancel = true. Another hook for dropping OLE droptargets can be implemented with registering a object derived from IGridDataObjectConsumer. There you can control the "Drop" part of the Drag&Drop operation. Stefan

AD Administrator Syncfusion Team December 10, 2002 05:05 PM UTC

One mistake ... I meant QueryCanOleDragRange, not OnQueryOleDataSourceData Stefan

SW Steve Weixel December 10, 2002 05:07 PM UTC

>What you are looking for is specific behavior for that cell similar to Clickable, Enabled or other properties of a style. Maybe something like "Locked" property so that the cell can't be moved. I'll make a note about this and see if we can such a property in a future version. Thank you for the reply. We will attempt your suggestions. However, this behavior that we are asking for is not just a "nice to have", it is absolutely vital for us to meet section 508 compliance (government accessibility standards). The real problem is that the behavior of enabled is wonky; it shouldn't prevent the user from using the keyboard to navigate. Maybe this is something we can do to the source in the meantime. On that subject, we ordered a source license with out other licenses, but we were never given instructions on how to download or otherwise access it. - Steve

AD Administrator Syncfusion Team December 10, 2002 08:26 PM UTC

Sales will get in touch with you. On another note, the "Enabled" flag has its use the way it is. What you look for is kind of "Locked" behavior which I agree also has its use. Of course we do not have all features in place the way everyone expects it, but the key is you have events that let you customize the grid such that you can change its behavior the way your requirements are. That said, I would recommend using event hooks instead of changing source code but it is your choice of course. And if you need further help just open a support incident. (This issue is otherwise getting too specific for a forum discussion). Stefan

AD Administrator Syncfusion Team December 11, 2002 02:38 PM UTC

Stefan, I have had the similar kind of problem regarding static cells before. I did not want my users to paste into static cells i.e. modify text of static cells. With your help, I wrote my own event handlers. "Static" cell name is kind of misleading. You may want to come up with some other built in cell type for us, which is enabled but readonly. cheers, - Reddy

TL Tom Le Blanc July 22, 2003 05:04 PM UTC

Guys, Tying up some loose ends as we near our production release. Did you ever look at this matter? [Renaming the type or making static a little more static?] It would still be great to have a cell that the user can select (to copy and paste elsewhere, or just to highlight) but have it remain nailed down in the grid. Thanks, Tom

AD Administrator Syncfusion Team July 22, 2003 09:48 PM UTC

There has been no change in our library with respect to the Static cell. If you want a cell that never changes, then you can subscribe to the SaveCellInfo event, and set e.handled = true for those cells. Below is a snippet that makes Static cells immutable. You can copy and paste them, but the cells themselves cannot be cut or pasted over or ???. Make sure you subscribe to this event after you set the values into the cells (or you values will not be set).
private void gridControl1_SaveCellInfo(object sender, GridSaveCellInfoEventArgs e)
	if(e.RowIndex > 0 && e.ColIndex > 0)
		if(this.gridControl1[e.RowIndex, e.ColIndex].CellType == "Static")
			e.Handled = true;

Live Chat Icon For mobile
Up arrow icon