# Open

## Opening

Used to initialize data, does not work with visual controls.

The method is followed by Opened()

```csharp
public override bool Opening()
{
    // at this moment, a user's permission to open the module could be denied
    
    rmView = new dsRmView();
    rmView.Material.Table.Columns.Add("rueckm_material", typeof(DataRowView));
    rmView.Fertigartikel.Table.Columns.Add("rueckm_fertigartikel", typeof(DataRowView));
    
    // the BusinessObject is created after the execution of:
    return base.Opening();
}
```

## Opened

Used for visual initializations.

The module is loaded, but not displayed yet.  The method is followed by PostOpen()

```csharp
public override void Opened()
{
    base.Opened();
    
    // Retrieve data; 
    BusObj.DataSetRetrieved += (sender, e) 
        => Bind();

    // set DataSource for controals
    Bind();
    
    // visual initializations
    dgMaterialFertigCsnr.ShownEditor += (sender, e) 
        => this.InvokeOnMainThreadWithDelay(RefreshMaterialFertigCsnrFilter);
    
    dgMaterialBadge.BadgeClicked += (sender, e) 
        => OpenMaterialDetails();
    dgFertigArtikelBadge.BadgeClicked += (sender, e) 
        => OpenFertigartikelDetails();
    
   // create new row in the DataSet
    NewKopf();
}
```

{% hint style="success" %}
Best practice: when opening a module, create a new row in the DataSet; otherwise we edit a non-existent row and the changes cannot be saved
{% endhint %}

## PostOpen

Is the place where we can set focus

The module is loaded and displayed.

```csharp
public override void PostOpen()
{
    base.PostOpen();
    FocusFirstEditableField();
}
```

```csharp
public virtual void FocusFirstEditableField()
{
    tbsBetriebsauftrag.Focus();
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tldocs.gitbook.io/documentation/framework/window-handling-object/opening.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
