Create and using of DataLink at RunTime

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
chris901
Posts: 64
Joined: Wed 20 Jul 2016 04:21

Create and using of DataLink at RunTime

Post by chris901 » Tue 16 Aug 2016 16:52

Hello,

I have a form where i bind data using the DataLink and SqlDataTable.

I create this component at DesignTime and drop it on the form.

Everything works fine and as expected.

When i try to create the DataLink at RunTime it isn't working at all.

I set the same properties like at DesignTime:
DataSource set to SqlDataTable and Synchronized = True.

Manipulating and navigating with the RunTime created DataLink doesn't work.

Am i missing setting some property when creating the DataLink at RunTime?

Thanks.

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: Create and using of DataLink at RunTime

Post by Pinturiccio » Thu 18 Aug 2016 15:36

First you need to create DataLink and PgSqlDataTable objects in your Form1 class.

Code: Select all

DataLink dataLink1;
PgSqlDataTable dt;
After this initialize these objects in the Form1 constructor or in the Form1_Load event handler. A simple application using DataLink in runtime can look like the following (We have added only 2 DataGridView and 1 Button components on the form at design-time)

Code: Select all

public partial class Form1 : Form
{
    DataLink dataLink1;
    PgSqlDataTable dt;

    public Form1()
    {
        InitializeComponent();
        dataLink1 = new DataLink();
        dt = new PgSqlDataTable("select * from tableName", "your connection string");
        dataLink1.DataSource = dt;
        dataLink1.Synchronized = true;
        dataGridView1.DataSource = dataLink1;
        dataGridView2.DataSource = dataLink1;
        dt.Fill();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        dataLink1.CurrentRow.Refresh();
    }
}
Does this example work for you?

chris901
Posts: 64
Joined: Wed 20 Jul 2016 04:21

Re: Create and using of DataLink at RunTime

Post by chris901 » Thu 18 Aug 2016 15:44

Hi Pinturiccio,

thanks for your example.

I also just found out that i could set the Owner property of DataLink manually and then it started working.

Post Reply