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

Datasource column to TableDescriptor column mapping

Hi,

Is there a (quick and efficient) way I can find which column index in my visible column collection maps to a particular column in my datasource?

I am using a datatable as source, and would like to know which column on my grid maps to a column in my datatable. As the columns can be rearranged, I cannot hardcode this. Is there some mapping available somewhere?

Thanks,
Mitul

5 Replies

AD Administrator Syncfusion Team October 12, 2007 09:38 AM UTC

You can use VisibleColumns.IndexOf to locate a particular field in the grid.


int loc = gridGroupingControl1.TableDescriptor.VisibleColumns.IndexOf("columnName");




MI mitul October 15, 2007 10:55 AM UTC

Hi Clay,

Is this the most efficient way there is? I have tried this and the lookup seems quite CPU intensive. I'd be doing this operation up to 3 times a second...

Also, any update to my other thread regarding the customised filter bar example?

Thanks,
Mitul

>You can use VisibleColumns.IndexOf to locate a particular field in the grid.


int loc = gridGroupingControl1.TableDescriptor.VisibleColumns.IndexOf("columnName");




AD Administrator Syncfusion Team October 15, 2007 01:25 PM UTC

You could maintain your own hashtable/dictionary that would map names to visiblecolumn prosition. You could use the above method to initailly populate the original mapping object. Then listen to the TableDescriptor.VisibleCOlumnsChanged event to reset your mapping object as needed if you are allowing your user to move columns or hide/show columns.

But unless you have a large number of visible columns, I would not think VisibleColumns.IndexOf would be a big cpu load. (Now, the first time the method is accessed may be a big load, because the GridGroupingControl uses a lazy architecture when it comes to actually populating structures, postponing the work until they are actually needed. So, the first access may actually trigger things like sorts/groupings/data loading, etc. But, thereafter, it should essentially be a quick index lookup using IndexOf on a small collection). So, the real question might be what else are you doing 3 times a second?


MI mitul October 15, 2007 03:09 PM UTC

I am currently performing the following operation:

Grid.TableControl.RefreshRange(Grid.TableControl.ViewLayout.VisibleCellsRange);

But want to do something that refreshes less of the grid, so am trying:

.TableControl.RefreshRange(GridRangeInfo.Col(Grid.TableDescriptor.VisibleColumns.IndexOf("Price"));

I would be doing this for up to 8 columns (out of roughly 35).

I have to use this method of refreshing because we have disabled the built in update mechanism, as the event to update the grid was firing on *each* individual change of the underlying datatable, despite using BeginUpdate and EndUpdate. (I update every datarow and multiple columns in each row) - this was very CPU intensive.

Do you have any suggestions on how refreshing the grid can be made more efficient?

Thanks,
Mitul
>You could maintain your own hashtable/dictionary that would map names to visiblecolumn prosition. You could use the above method to initailly populate the original mapping object. Then listen to the TableDescriptor.VisibleCOlumnsChanged event to reset your mapping object as needed if you are allowing your user to move columns or hide/show columns.

But unless you have a large number of visible columns, I would not think VisibleColumns.IndexOf would be a big cpu load. (Now, the first time the method is accessed may be a big load, because the GridGroupingControl uses a lazy architecture when it comes to actually populating structures, postponing the work until they are actually needed. So, the first access may actually trigger things like sorts/groupings/data loading, etc. But, thereafter, it should essentially be a quick index lookup using IndexOf on a small collection). So, the real question might be what else are you doing 3 times a second?


AD Administrator Syncfusion Team October 16, 2007 02:37 PM UTC

Try code like this to see if it works quicker for you.

this.gridGroupingControl1.TableControl.UpdateWithDrawClippedGrid(gridGroupingControl1.TableControl.ClientRectangle);

Loader.
Live Chat Icon For mobile
Up arrow icon