Bind a return value to a DataGrid using form server methods
To display a data table in a Silverlight form, you must bind the return value using server methods.
Before you begin
About this task
Note: The information in this topic is not related to WPF forms unless otherwise stated.
Procedure
- In the navigator, click .
- From the Forms list, select the resource you want to work with.
- Click .
- Click Add.Your Windows browser appears.
- From the <install dir>\Microsoft SDKs\Silverlight\v5.0\Libraries\Client folder, select System.Windows.Controls.Data.dll, and then click Open.
- Optional: In the Description field, enter new information about the file, and then click Save.
- Click the Designer tab.
- Click the Server Methods tab.
- Click Add.
- In the Properties panel, in the Source field, click the ellipsis button.The Pick a method dialog box appears.
- Expand IDatabaseService, select ExecuteStatement, and then click Next.
- In the Statement section, click Browse next to the Use Existing radio button.The Universal Browser appears.
- Select a statement, click OK, and then click Finish.
- In the Connection field, click the ellipsis button.The Universal Browser appears.
- Expand OK. , select a connection, and then click
- From the EventTriggers field, click the Add button.The Event Triggers dialog box appears.
- Select the event that you want to trigger the method.
- Click Save.
- Click the Project tab.
- Expand .
- Double-click MainPage.xaml.cs.
- Add the code in bold to this page in the location indicated. Edit column names and add additional columns as appropriate for your call.
namespace YOURPROJECTNAME { public partial class MainPage : UserControl, IFragment { [Import] public IFeedbackService FeedbackService { get; set; } readonly ILog _logger = LogManagerEx.GetLogger("YOURPROJECTNAME"); readonly Dictionary<Type, object> _interfaceHelpers = new Dictionary<Type, object>(); public MainPage() { ProficyComposition.SatisfyImports(this); InitializeComponent(); _interfaceHelpers[typeof(IResourceParameters)] = new FragmentMetadataByAttributes(this); _interfaceHelpers[typeof(IFragmentInitialization)] = new FragmentInitialization(this); InitializeProficyData(); DataGrid1.AutoGenerateColumns = false; DataGrid1.Columns.Add(new DataGridTextColumn() { Header = "Header1", Binding = new Binding("[YOURCOLUMNNAME]") }); DataGrid1.Columns.Add(new DataGridTextColumn() { Header = "Header2", Binding = new Binding("[YOURCOLUMNNAME2]") }); } public T GetInterface<T>() where T : class { if (_interfaceHelpers.ContainsKey(typeof(T))) { var iface = _interfaceHelpers[typeof(T)] as T; Debug.Assert(iface != null, "_interfaceHelpers[" + typeof(T).Name + "] didn't have an object of the right type."); return iface; } return this as T; } } }
- Click Save.
- Click the MainForm.xaml tab.
- Click the Toolbox tab.
- Expand Custom Controls, and then select DataGrid.
- For a WPF form, expand Grids and Panels.
- Drag the DataGrid control onto MainPage.xaml.
- From the Properties panel, go to the ItemsSource property, click the drop-down arrow, and then select Bind.The Binding dialog box appears.
- Select .
- For a WPF form, bind the InputTable property of the Data Grid control to the result of the server method.
- Click Save.