RWS Community
RWS Community
  • Site

Trados Go

Trados Studio

Trados Ignite

Trados Team

Trados Accelerate

Trados Enterprise

Trados GroupShare

Passolo

MultiTerm

RWS AppStore

Connectors

Beta Groups

Managed Translation

MultiTrans

TMS

Trados Enterprise

WorldServer

Language Weaver

Language Weaver Edge

Language Weaver Connectors

Language Weaver in Trados Studio

 

 

Content Champions

Tridion Docs

Tridion Sites

Contenta

LiveContent

XPP

Trados Go Ideas

Trados Studio Ideas

Trados Ignite Ideas

Trados GroupShare Ideas

Trados Team Ideas

Trados Team Terminology Ideas

Trados Enterprise & Accelerate Ideas

MultiTerm Ideas

Passolo Ideas

RWS Appstore Ideas

Tridion Docs Ideas

Tridion Sites Ideas

Language Weaver Ideas

Language Weaver Edge Ideas

Managed Translation - Enterprise Ideas

TMS Ideas

WorldServer Ideas

Trados Enterprise Ideas

XPP Ideas

GroupShare Developers

Language Cloud Developers

MultiTerm Developers

Passolo Developers

Trados Studio Developers

Managed Translation Developers

TMS Developers

WorldServer Developers

Tridion Docs Developers

XPP Developers

Language Combinations by Language Services

RWS Training & Certification

Style Guides

Content Management Partners

LDE Korean Vendor Support

RWS Campus

Trados Approved Trainers

Nordic Tridion Docs User Group

Tridion West Coast User Group

Community Ops

RWS Community Internal Group

AURORA

Internal Trados Ideas

Linguistic Validation

Mercury

Phrase

QA Tools

RI Operational Excellence

Trados Inspired

XPP Cloud

Recognition & Reward System

RWS Community Platform Related Questions

Community Solutions Hub (Trados)

About RWS

Events

RWS Services: Train AI & others

RWS Training & Certification

To RWS Support

  • Search
  • Translate

    Detecting language please wait for.......


    Powered by
  • User
  • Site
  • Search
  • User
  • Developers
  • Trados Portfolio
  • Trados Studio Developers
  • More
  • Cancel
Trados Studio Developers

Trados Studio Developers > Studio Developers WIKI

How bind a DataGridView to SettingsGroup
  • Home
  • Trados Studio developers forum
  • Studio Developers WIKI
  • Studio Developers Blog
  • More
  • Cancel
  • New
Show Translation Options

Detecting language please wait for.......


Powered by
Trados Studio Developers requires membership for participation - click to join
  • -Trados Studio API
    • Developer Licences
    • +Getting Started
    • -Knowledgebase
      • -How to...
        • How to create a project using public api
        • How to create a View plugin in Studio using WPF
        • How to sign an class library using Sdl Community key
        • -How to use Batch Tasks plugins
          • How bind a DataGridView to SettingsGroup
          • How to edit the plain text from sdlxliff in Batch Task context
          • How to insert a placeholder in Segment in Batch Task context
        • How to use Studio Ribbon Tabs
        • How to use Tell Me API
        • How to use the Studio Useful Tips service
        • +How to use the Translation Memory API
      • +Studio 2015
      • +Studio 2019
      • +Studio 2021
      • +Trados Studio 2022

How bind a DataGridView to SettingsGroup

In page we'll explain how to use an DataGridView in your application. How to populate it with data and how to save and retrieve the data from Settings Group.

In this example we use the source code of Project Anonymizer plugin. More information about this plugin can be found here.The plugin code is open source on our Git Hub repository it can be found here.

In other words we want to achieve this: 

First step is to drag&drop a DataGridView control from Toolbox into our Control Page. Please make sure the control page implements ISettingsAware<> interface. Next we'll override OnLoad() method;

 

In the above code we set  AutoGenerateColumns=false because we want to create the columns manually. We created an TextBoxColumn and add it to grid columns. "DataPropertyName" is used to bind the content of the cell with the property named "Pattern" set on DataSource.

We'll bind a collection to DataSource property on the grid and all the operations we made on the grid like remove, edit, add we'll do on that collection and the grid will be updated automatically. 

Why we use a BindingList<> and not List<> ? 

1. The main reason we use it to data bind is that it implements the IRaiseItemChangedEvents interface. That means every time the collection has changed  the data grid is automatically refreshed. We don't need to reload the grid explicit, or to go on a specific row index and remove that row or edit it.

2. If AllowUserToAddRow property is set to true,an empty row will appear at the end of the grid. In that row the user can fill the data and  automatically an empty row will appear bellow.

How to tie the list used as data source with Batch Task Settings

In the previous page we mention a class which inherits from Settings Group class. In that class you need to store properties for each controls you have on the UI. For example  the list used in the data source, or if you have a checkbox there you'll have a property which will be used to set the value on Settings. Later you can retrieve the value an initialize the checkbox with the value saved.

Below is an example on how we set the binding list to Settings:

But this step is not enough. We need to override GetDefaultValue() method.

 

What does GetDefaultValue() do?

This method is called automatically then you get or set a value to Settings Group. Because in our example we use a list we need to initialize it before we can use it. If we don't add the above code when we retrieve the RegexPattern from the settings it will be null.

After we set the list on Settings Group we want to populate the data grid with the expressions already saved on the settings. On order to do it we'll go back on User Control and add the following code:

This method should be called from OnLoad() method

In SetSettings method is shown how to use SettingsBinder class to get the value from Settings and assign it for example to a text box "Text" property defined on the UI.

How to handle Edit on Data Grid View

Bellow code shows how to handle delete on data grid. We subscribed on KeyDown event.

 

Code above check if the key pressed is "Delete", it takes all the rows selected and using row.DataBoundItem object we get the corresponding object from the source and removes it from the RegexPatterns list.

In the beginning of the documentation we mentioned that we use BindingList because it raises events when the collections is changed. This works as a charm in a simple Windows Forms application but because our plugin uses Studio Api's the default functionality is overwritten by the API's.

If you subscribe to DataSourceChanged event on grid and put a break point you'll see that the event is not fired even you make a change to your data source collection.

Why this thing happens? 

In Visual Studio if you select SettingsGroup and hit F12 you'll see this class implements following interfaces ISettingsGroup, INotifyPropertyChanged, IEditableObject. Because we inherits SettingsGroup class the normal behavior of BindingList is overwritten.

In our Settings Class we added GetDefaultValue() method. This method is fired every time when an object which inherits Settings Group has changed. So to reload automatically the interface we need to assign back the updated list to Settings object like this Settings.RegexPatterns = RegexPatterns, this will fire GetDefaultMethod() and our grid will be refreshed.

Tags:

batch task
Studio Documentation
Studio API
openexchange
  • Share
  • History
  • More
  • Cancel
Related
Recommended
  • Our Terms of Use
  • Copyright
  • Privacy
  • Security
  • Anti-slavery Statement
  • Cookie Notice
  • YouTube