Select to view content in your preferred language

(Rad)GridView and displaying the attributes of all the Graphics

749
2
04-25-2013 02:05 PM
Labels (1)
BKuiper
Frequent Contributor
Hi,

I want to achieve something similar as in ArcMap where you can examine all the attributes for each graphic. How would you achieve this in WPF ? Due to the fact that Attributes is a Dictionary<string, object> and lies underneath the Graphic. You can't easily bind to this and auto populate the grid. I'm looking into using IBindingList, but i was curious of somebody tried something similar before so i don't have to reinvent the wheel.

In other words, did you created a DataGrid that has as columns each Attribute key and as each row the graphic with its values for that attribute key. knowing that the attributes are dynamic for different layers. If so, how did you do this.

Thanks
0 Kudos
2 Replies
BKuiper
Frequent Contributor
Hi,

I want to achieve something similar as in ArcMap where you can examine all the attributes for each graphic. How would you achieve this in WPF ? Due to the fact that Attributes is a Dictionary<string, object> and lies underneath the Graphic. You can't easily bind to this and auto populate the grid. I'm looking into using IBindingList, but i was curious of somebody tried something similar before so i don't have to reinvent the wheel.

In other words, did you created a DataGrid that has as columns each Attribute key and as each row the graphic with its values for that attribute key. knowing that the attributes are dynamic for different layers. If so, how did you do this.

Thanks


DataTable to the rescue

            DataTable dt = new DataTable();

            if (layer.Graphics.Any())
            {
                foreach (var attribute in layer.Graphics[0].Attributes)
                {
                    dt.Columns.Add(attribute.Key);
                }

                foreach (var graphic in layer.Graphics)
                {
                    dt.Rows.Add(graphic.Attributes.Values.ToArray());
                }
            }

            this.Data = dt;
0 Kudos
KeithGemeinhart
Regular Contributor
I think the FeatureDataGrid already does what you are looking for.

Check out the WPF Sample application that comes with runtime (usually in C:\ArcGIS\WPF10.1.1\sdk\samples\sampleapplication). Then navigate to the Editing -> Edit Controls -> Feature Data Grid sample.
0 Kudos