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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Showing dirty cells

Thread ID:





6268 Aug 6,2003 10:08 PM UTC Aug 8,2003 02:37 PM UTC WinForms 6
Tags: GridControl
Administrator [Syncfusion]
Asked On August 6, 2003 10:08 PM UTC

I have a datagrid with datbound columns. Whenever a use edits changes a cell my grid, I want to show the chnage by changing the cells background & foreground. I have tried the code below and nothing seems to work. Any ideas? private void MainGrid_CurrentCellEditingComplete(object sender, System.EventArgs e) { GridStyleInfo style = MainGrid[MainGrid.CurrentCell.RowIndex, MainGrid.CurrentCell.ColIndex]; BrushInfo bi = new BrushInfo(GradientStyle.PathRectangle, Color.White, Color.Silver); style.Interior = bi; MainGrid.RefreshRange(GridRangeInfo.Cell(MainGrid.CurrentCell.RowIndex, MainGrid.CurrentCell.ColIndex), true); }

Administrator [Syncfusion]
Replied On August 7, 2003 06:25 AM UTC

In a GridDataBoundGrid, you cannot set individual cell properties (other than Text or CellValue). The reason is that the only 'cell storage' is your datasource, and it only knows the value. It does not track BackColor or any other properties. So, to do this, you could maintain a list of changed objects, and then in PrepareViewStyleInfo, you could check to see if the cell being requested is in your list, and if so, color it there. Attached is a little sample. It uses a simple arraylist to track the changes with the primary key for the row and mappingname for the column forming the lookit item to see if a cell has been changed. Using such a lookup item allows you to sort the grid or move columns without having to constantly modify the changedcells list. If the ArrayList is too slow (you are doing hundreds/thousand of changes), then you could use a hashtable that might be quicker. Another comment is that to monitor the changed cells and add then to the list, the sample uses Model.SaveCellInfo. The reason is that this event will capture things like selecting a range of cells and pressing Delete to clear them, and CurrentCellEditingComplete is not hit in such cases.

Administrator [Syncfusion]
Replied On August 8, 2003 12:40 AM UTC

Thanks. Would StyleModifyType work in SaveCellinfo?

Administrator [Syncfusion]
Replied On August 8, 2003 06:43 AM UTC

I am not sure what you mean by 'StyleModifyType work in SaveCellInfo'. I am not sure there is a use for it there exacpt to possibly modify the e.Style.CellValue as that is the only thing that is used in a GridDataBoundGrid at this point. In a GridDataBoundGrid, there is nothing stored for a cell except the CellValue. The backcolor is not stored (unless you do it directly yourself, allocating some datastructure to hold it, etc). So, in a GridDataBoundGrid, the purpose of SaveCellInfo, is you give you the chance to modify e.Style.CellValue before it goes into your datatsource, and also to let you know that this is about to happen. You can also use it to store things like e.Style.BackColor for a particular cell (e.RowIndex, e.ColIndex) if you want to do store these values yourself. But the GridDataBoundGrid will not put them anywhere.

Administrator [Syncfusion]
Replied On August 8, 2003 07:44 AM UTC

I see. Thank you for the excellent explanation. Please correct me if I am wrong but I think I may be looking for the flexibilility of your GridControl (which gives is more customizable - it remembers cell by cell styles, correct?) and also the databinding of your databound grid. If the above is correct, would it start to be easier to modify the GridControl to be databound raher than me slow the databoundgrid for custinization? (i.e. GridControl has ChangeSTyles() - griddatabound does not) Is their a way to make GridControldatabound - auto fill and update to a datasource with only a medium amount of customization?

Administrator [Syncfusion]
Replied On August 8, 2003 08:00 AM UTC

If you use a GridControl in a non-virtual manner, then the grid does can store style information on a cell by cell basis. You can call the GridControl.PopulateValues method to move a datatable into the internal storage of a grid. If you do so, then you can explicitly set style properties on individual cells. The draw back is that there is not 'automatic' way of moving any changes from your GridControl back to the DataTable. If your grid is for display purposes only, then this is not a problem. But, if you want your user to be able to edit cells, then it is. One solution is to handle the SaveCellInfo event which is called any time a value is changed in the GridControl. You could then explicilty save the changed value back to the DataTable (in addition to letting the grid store it internally). One technical problem arises if you are allowing users to move rows and/or columns, but that can be handled as well through including a primary key column in your grid (maybe hiding from the user, but having it available to identify the proper record in the datatable). If you use a GridDataBoundGrid, these getting the data back into the DataSource is managed for you, but to set cell-specific properties requires you to handle an event. So, I think you would have to judge which path is less complicated in your specific use case.

Administrator [Syncfusion]
Replied On August 8, 2003 02:37 PM UTC

Great points. Thank you.


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

Live Chat Icon For mobile
Live Chat Icon