Select to view content in your preferred language

GIS related data from RIA service

3272
2
12-21-2010 11:13 AM
Chula_VistaGIS
Occasional Contributor
I have gis data in an sql-server database I need to bind to a datagrid.  I can use an ria service and bind the data directly to the datagrid but ideally, I would like to loop through the fields in these  entities and create hyperlinks for certain fields prior to adding the data to the datagrid.  Does anyone have any thoughts on how to approach this problem ?

Thanks,
0 Kudos
2 Replies
STharshini
Emerging Contributor
One of the ways to do...

1) For your datagrid, set the AutoGenerateColumns="false"

As an example

<sdk: DataGrid x:Name="RIADataGrid" AutoGenerateColumns="false" ...>

2) Populate your columns

As an example

<sdk: DataGrid x:Name="RIADataGrid" AutoGenerateColumns="false" ...>
<sdk: DataGrid.Columns>
<sdk: DataGridTextColumn x:Name="FirstField" Binding="{Binding FirstField}" Header=" First Field"/>
<sdk: DataGridTextColumn x:Name="SecondField" Binding="{Binding SecondField}" Header=" Second Field"/>
<sdk: DataGridTextColumn x:Name="ThirdField" Binding="{Binding ThirdField}" Header=" Third Field"/>

...
</sdk: DataGrid.Columns>
</sdk: DataGrid>

3) Depending on your field type and Silverlight Version, you can use one of the following

a) DataGridTextColumn
b) DataGridCheckBoxColumn
c) DataGridTemplateColumn


Check the following link
http://msdn.microsoft.com/en-us/library/system.windows.controls.datagridtemplatecolumn(v=VS.100).asp...

4) Thus, if you want to have a hyperlink, you may want to use "DataGridTemplateColumn" or "DataGridHyperlinkColumn"

As an example

<sdk: DataGrid x:Name="RIADataGrid" AutoGenerateColumns="false" ...>
<sdk: DataGrid.Columns>
<sdk: DataGridTextColumn x:Name="FirstField" Binding="{Binding FirstField}" Header=" First Field"/>
<sdk: DataGridTextColumn x:Name="SecondField" Binding="{Binding SecondField}" Header=" Second Field"/>
<sdk: DataGridTextColumn x:Name="ThirdField" Binding="{Binding ThirdField}" Header=" Third Field"/>

<sdk: DataGridTemplateColumn x:Name="FourthField" Header=" Fourth Field">
<sdk: DataGridTemplateColumn.CellTemplate>
<DataTemplate>
//add a Hyperlink Control
</DataTemplate>
</sdk: DataGridTemplateColumn.CellTemplate>
</sdk: DataGridTemplateColumn>
...
</sdk: DataGrid.Columns>
</sdk: DataGrid>


5) Check the following link as well

http://msdn.microsoft.com/en-us/library/system.windows.controls.datagridtemplatecolumn(v=vs.95).aspx

http://msdn.microsoft.com/en-us/library/system.windows.controls.datagridtemplatecolumn(v=VS.100).asp...


I have gis data in an sql-server database I need to bind to a datagrid.  I can use an ria service and bind the data directly to the datagrid but ideally, I would like to loop through the fields in these  entities and create hyperlinks for certain fields prior to adding the data to the datagrid.  Does anyone have any thoughts on how to approach this problem ?

Thanks,
0 Kudos
Chula_VistaGIS
Occasional Contributor
One of the ways to do...

1) For your datagrid, set the AutoGenerateColumns="false"

As an example

<sdk: DataGrid x:Name="RIADataGrid" AutoGenerateColumns="false" ...>

2) Populate your columns

As an example

<sdk: DataGrid x:Name="RIADataGrid" AutoGenerateColumns="false" ...>
<sdk: DataGrid.Columns>
<sdk: DataGridTextColumn x:Name="FirstField" Binding="{Binding FirstField}" Header=" First Field"/>
<sdk: DataGridTextColumn x:Name="SecondField" Binding="{Binding SecondField}" Header=" Second Field"/>
<sdk: DataGridTextColumn x:Name="ThirdField" Binding="{Binding ThirdField}" Header=" Third Field"/>

...
</sdk: DataGrid.Columns>
</sdk: DataGrid>

3) Depending on your field type, you can use one of the following

a) DataGridTextColumn
b) DataGridCheckBoxColumn
c) DataGridTemplateColumn

4) Thus, if you want to have a hyperlink, you may want to use "DataGridTemplateColumn"

As an example

<sdk: DataGrid x:Name="RIADataGrid" AutoGenerateColumns="false" ...>
<sdk: DataGrid.Columns>
<sdk: DataGridTextColumn x:Name="FirstField" Binding="{Binding FirstField}" Header=" First Field"/>
<sdk: DataGridTextColumn x:Name="SecondField" Binding="{Binding SecondField}" Header=" Second Field"/>
<sdk: DataGridTextColumn x:Name="ThirdField" Binding="{Binding ThirdField}" Header=" Third Field"/>

<sdk: DataGridTemplateColumn x:Name="FourthField" Header=" Fourth Field">
<sdk: DataGridTemplateColumn.CellTemplate>
<DataTemplate>
//add a Hyperlink Control
</DataTemplate>
</sdk: DataGridTemplateColumn.CellTemplate>
</sdk: DataGridTemplateColumn>
...
</sdk: DataGrid.Columns>
</sdk: DataGrid>


5) Check the following link as well

http://msdn.microsoft.com/en-us/library/system.windows.controls.datagridtemplatecolumn(v=vs.95).aspx


Thanks for the suggestion. 

Unfortunately, I need to handle this in code behind since I don't know what field(s) may be returned and/or need a hyperlink.  In code behind, I am able to create the datatemplate and hyperlink field by iterating through the dictionary object returned by an esri query. 

What I'm looking for is a way to create a dictionary and iterate through entitiy objects returned from an ria service (loadoperation).

Regards,
0 Kudos