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

GDBG, cell attributes, binding

Thread ID:

Created:

Updated:

Platform:

Replies:

23169 Jan 6,2005 01:49 AM UTC Jan 6,2005 04:21 PM UTC Windows Forms 5
loading
Tags: GridControl
Brandon
Asked On January 6, 2005 01:49 AM UTC

Hi all, I just started using Databound Syncfusion grids and I''ve run into a brick wall. I''ve written a multithreaded application which dynamically gathers information about rows in the grid. I want to be able to change cell attributes like font and background color based on the information my worker threads return. I think it''s easy to see how much a pain it will be to implement the attributes in the PrepareViewStyleInfo event. Basically I''ll end up creating a dataset that holds a list of attributes and applies each of them when that event is raised. I don''t want to do this -- that''s why I''m using a control that''s already written for me in the first place. Is there someway to "unbind" a datagrid (maybe not have it bound in the first place; just filled) that opens up ability to change attributes like grid(1,2).BackColor = blah? The more I think about it, my dataflow is from the database to the screen, but not in the opposite direction. Any insight is greatly appreciated. Thanks.

Administrator [Syncfusion]
Replied On January 6, 2005 06:51 AM UTC

A GridDataBoundGrid does not maintain GridStyleInfo objects on a cell by cell basis. This would be what you would need to be able to set style properties on a cell by cell basis. You have two options. One is to maintain these properties yourself, and use PrepareViewStyleInfo to dynamically provide these properties to the grid from your data store. This is what you say you do not want to do. The other is to use a GridControl which does maintain style information on a cell by cell basis. There are a couple of ways to actually use the GridControl in this situation. One is to move the data from your datatable into the GridControl. (You can use grid.PopulateValues to do this.) The other is to not actually move the data, but to handle QueryCellInfo and provide the value from your DataTable at that point. (The gridcontrol would not actually be virtual since the memory has been allocated to hold the styles, but the cell values would be dynamically provided directly from the datatable.)

Brandon
Replied On January 6, 2005 11:17 AM UTC

Thanks for your response Clay. Can I just drop in a datagrid control in place of the gdbg? Does is have the same events, functions, so on? I have overloaded several of the mouse events for the gdbg to get it to behave exactly the way I want it to. I''m hoping that the datagrid and gdbg are essentially the same class without the binding. Can you confirm this? Thanks again.

Administrator [Syncfusion]
Replied On January 6, 2005 11:34 AM UTC

No, you should not expect this to work without some (maybe significant depending upon what you are doing) recoding. For example, DataGrid has no PrepareViewStyleInfo event. And you will not be able to set cell specific properties in a DataGrid without significant more work than what you would have to do with a GridDataBoundGrid.

Brandon
Replied On January 6, 2005 03:45 PM UTC

Clay, thanks again. This GridControl is working quite well and only required a few minor modifications from the databound grid. A few small issues have come up however. Is there an example or sample somewhere that illustrates the following with GridControl? - populating column headers from a dataset - referencing cell data on a given row by its column name (not index) - allowing the user to drag and reorder columns (this was working in the GDBG by overriding the mouseup and mousedown events and changing the ListBoxSelectionMode to None, but it no longer works in the Grid Control... clicking the column header just selects the header row. I could probably figure it out, but if there was an example it becomes that much easier). Thanks again for all your help.

Administrator [Syncfusion]
Replied On January 6, 2005 04:21 PM UTC

1) The headers in in a GridControl are row 0. So, you would set something like: grid[0, 3].Text = "SomeTitle"; to set the header for column 3. You could get the ColumnName from the DataTable.Columns for the column. 2) You will have to write your own NameToColIndex method to convert a name into its proper column index. If you are using the name for the hreader text as in 1, your method could loop through the cells in row zero looking for the proper text and then return the colinex where it was found. Or, you could create a HashTable that uses the Name as a key and the proper column index as the value, and you could use the hastable to just look up the index. (Note, if you are going to allow moving column, then if you search row 0 verytime you want a colindex from a name, you do not have to do anywork when you move teh columns. If you cache the name-colindex pairs in a hashtable, you would have to update teh hashtable when a column is moved.) 3) If you drag a gridcontrol onto a form and add this code, then you can click a column header to select it, and then mousedown on it and move it to another position. private void Form1_Load(object sender, System.EventArgs e) { for(int i = 1; i <= this.gridControl1.ColCount; ++i) this.gridControl1[0, i].Text = string.Format("Title{0}", i); this.gridControl1.ListBoxSelectionMode = SelectionMode.MultiExtended; this.gridControl1.AllowDragSelectedCols = true; this.gridControl1.CellClick += new GridCellClickEventHandler(gridControl1_CellClick); } private void gridControl1_CellClick(object sender, GridCellClickEventArgs e) { if(e.RowIndex == 0 && e.ColIndex > 0) this.gridControl1.Selections.SelectRange(GridRangeInfo.Col(e.ColIndex), true); }

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

;