Select to view content in your preferred language

FeatureDataGrid updating row

993
4
10-08-2012 07:06 AM
SteveRofe
Deactivated User
I am using the following code to show hyperlink buttons in a FeatuerDataGrid. This code works fine, except in the case that only one feature is selected, in which case the datatemplate is not applied. Does anyone have any suggestions to get this working?

 
       private void featureDataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            if (!_hasFixedColumns)
            {
                FeatureDataGrid fdg = sender as FeatureDataGrid;
                Dictionary<int, DataGridColumn> newFeatureDataGridColumns = new Dictionary<int, DataGridColumn>();

                if (_urlColumns.Count > 0)
                {
                    foreach (DataGridColumn column in fdg.Columns)
                    {
                        DataGridTemplateColumn newColumn = new DataGridTemplateColumn();
                        if (column.Header != null && _urlColumns.ContainsKey(column.Header.ToString()))
                        {
                            newColumn.CellTemplate = getColumnDataTemplate(_urlColumns[column.Header.ToString()]);
                            newColumn.Header = column.Header;
                            newFeatureDataGridColumns.Add(column.DisplayIndex, newColumn);
                        }
                        else if (column.Header != null && _fdgColumns.ContainsKey(column.Header.ToString()))
                        {
                            newColumn.Header = column.Header;
                            newColumn.Width = new DataGridLength(4, DataGridLengthUnitType.Auto);
                            newFeatureDataGridColumns.Add(column.DisplayIndex, column);
                        }                       
                    } 
                }

                if (newFeatureDataGridColumns.Count > 0)
                {
                    foreach (KeyValuePair<int, DataGridColumn> Item in newFeatureDataGridColumns)
                    {
                        fdg.Columns.RemoveAt(Item.Key);
                        fdg.Columns.Insert(Item.Key, Item.Value);
                    }
                }
            }
        }
0 Kudos
4 Replies
deleted-user-ATjHIWsdQYmT
Deactivated User
I'm not sure, but Columns.count might be a zero based index..

try:
if (_urlColumns.Count >= 0)

and
if (newFeatureDataGridColumns.Count >= 0)
0 Kudos
SteveRofe
Deactivated User
Just to clarify the problem; the issue is not that this code does not run, it's that the templates are not applied if only one feature is selected (even though the loop creating them is entered). If two or more features are selected, the templates are applied.

I need to find the event that is being triggered after featureDataGrid_LoadingRow, which causes the templates to be applied. Alternatively, I need a method that will force the update e.g. something like 'Row.Refresh()'
0 Kudos
ChristopherHill
Deactivated User
In our next release there will be support for detecting if string data is a uri and display a hyperlink button instead of a textblock.
0 Kudos
SteveRofe
Deactivated User
Unfortunately Chris, that's not of a lot of use to me now.

To anyone else who may come across this issue, the workaround (read 'ugly hack') that I used to get around this problem was to add a new graphic (no geometry, no attributes) to the featureset being used as the graphics layer source. This results in an extra blank row being displayed in the featuredata, but other than that, it seems to work OK.
0 Kudos