how to bind data from database table to windows DataGrid in pega22
@SrinivasR3193 The best way to bind data to a UI is via a LookupTable. To do this, create a LookupTable with the appropriate columns and define the column Type to match the DataType of your DataTable column. On your Form add a TableView component. If you are using one of the latest versions of 22 or R25, you can add a LookupTable to the Form directly, but you may also add it to the Globals if needed. Set the TableProvider property to the LookupTable. Then you can set the DataGridView’s Datasource property to the TableView.
If you are using the Query component, there is a method called GetTable that returns a DataTable representing the results of the query (assuming it is returning rows of data). You can then use the ReplaceTable method of a LookupTable to place the contents of the query into the LookupTable.
One thing to keep in mind is that all events that interact with the LookupTable in this case need to be triggered from the UI thread. That means a button click or other event from a form control need to control any data coming or going into the lookup table. If you are updating the LookupTable from another thread, then the easiest way to make sure everything is one the right thread is to make a copy of the LookupTable component (create a second one with the exact same columns). Add a button to your form and set the Tabstop property to False. Place this button behind another control. You can right-click it and select “Send to back” to make it appear beneath another control. Its precise placement is irrelevant since we don’t want the user to be able to click it, we just need to make sure it is technically visible (being behind something counts). The click event will not fire if the control is not “visible”. Whenever you are ready to update the table on the UI, call the PerformClick method on this button. The Click event from this button should call the GetTable method from your original LookupTable and pass that to the ReplaceTable method of the new table. Make sure this second table is the one connected to the TableView and DataGridView.
@ThomasSasnett is there a sample code for the above steps.
I’m getting the data from database table but not able to assign multiple rows to the lookup table
@SrinivasR3193 I don’t know of a public Database that I can connect to for a sample. Use the Query component to query your table and then use the Execute method to get the results and the GetTable to pass those results to your LookupTable.
