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.
Create and using of DataLink at RunTime
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
Re: Create and using of DataLink at RunTime
First you need to create DataLink and PgSqlDataTable objects in your Form1 class.
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)
Does this example work for you?
Code: Select all
DataLink dataLink1;
PgSqlDataTable dt;
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();
}
}
Re: Create and using of DataLink at RunTime
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.
thanks for your example.
I also just found out that i could set the Owner property of DataLink manually and then it started working.