Hi all, I am working on a personal project and would like to add a datasource to a combo box using commands and not the gui. is that possible? I am not going to use the gui at all, so i thought that it would just be an extra load just for this.
either way if i succeed in doing it, how is it possible to have a secondary combo bind to a dynamic select query?
For example, i have a 2 column table,
A-B
1-1A
1-1B
1-1C
2-2A
2-2B
3-3A
3-3B
i want to use a combo box to select a value from column A and then using this to do a select in order to get the corresponding data on column B and pass it to the combo box.
So what i want is load column A on combobox1 and when selecting 1 for example, setting the combo box2 to load just the 3 rows from column B. It would be nice if initially combobox2 has all the data from column B, but this is not a must have.
Thanks for the help, ilias
combobox datasource
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
Re: combobox datasource
You can write the logic, reading the related data when changing position in the combo box, yourself.
You also can implement this scenario using DataSet with a master/detail relation. dotConnect for PostgreSQL allows performing such operation when data is stored in two related tables. Here is a sample of such scenario.
C# code:
You also can implement this scenario using DataSet with a master/detail relation. dotConnect for PostgreSQL allows performing such operation when data is stored in two related tables. Here is a sample of such scenario.
Code: Select all
CREATE TABLE t_parent
(
a integer NOT NULL,
CONSTRAINT t_parent_pkey PRIMARY KEY (a)
)
CREATE TABLE t_child
(
b text,
a integer,
CONSTRAINT a_a_fkey FOREIGN KEY (a)
REFERENCES t_parent (a) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
INSERT INTO t_parent(a) VALUES (1);
INSERT INTO t_parent(a) VALUES (2);
INSERT INTO t_parent(a) VALUES (3);
INSERT INTO t_child(b, a) VALUES ('1A', 1);
INSERT INTO t_child(b, a) VALUES ('1B', 1);
INSERT INTO t_child(b, a) VALUES ('1C', 1);
INSERT INTO t_child(b, a) VALUES ('2A', 2);
INSERT INTO t_child(b, a) VALUES ('2B', 2);
INSERT INTO t_child(b, a) VALUES ('3A', 3);
INSERT INTO t_child(b, a) VALUES ('3B', 3);
Code: Select all
public partial class Form1 : Form
{
PgSqlConnection conn;
PgSqlDataTable Table;
PgSqlDataTable Table1;
PgSqlDataSet pgSqlDataSet1;
DataLink tableLink;
DataLink relation1Link;
public Form1()
{
InitializeComponent();
conn = new PgSqlConnection("your connection string");
Table = new PgSqlDataTable("select * from t_parent", conn);
Table.TableName = "Table";
Table.FetchAll = true;
Table.Active = true;
Table1 = new PgSqlDataTable("select * from t_child", conn);
Table1.TableName = "Table1";
Table1.FetchAll = true;
Table1.Active = true;
pgSqlDataSet1 = new PgSqlDataSet();
pgSqlDataSet1.Connection = conn;
pgSqlDataSet1.DataSetName = "NewDataSet";
pgSqlDataSet1.EnforceConstraints = false;
pgSqlDataSet1.Name = "pgSqlDataSet1";
pgSqlDataSet1.Tables.AddRange(new System.Data.DataTable[] {Table, Table1});
pgSqlDataSet1.Relations.Add("Relation1", Table.Columns["a"], Table1.Columns["a"], false);
pgSqlDataSet1.Owner = this;
tableLink = new Devart.Data.DataLink();
tableLink.DataSource = Table;
tableLink.Name = "tableLink";
tableLink.Synchronized = true;
tableLink.Owner = this;
relation1Link = new Devart.Data.DataLink();
relation1Link.DataMember = "Relation1";
relation1Link.DataSource = Table;
relation1Link.Name = "relation1Link";
relation1Link.Synchronized = true;
relation1Link.Owner = this;
comboBox1.DataSource = tableLink;
comboBox1.DisplayMember = "a";
comboBox1.FormattingEnabled = true;
comboBox2.DataSource = relation1Link;
comboBox2.DisplayMember = "b";
comboBox2.FormattingEnabled = true;
}
}
Re: combobox datasource
Thanks for the info, but there were some complications.
I started with this project working on a local postgres DB, with ultimate aim to move it online.
But it seems that i cant find a free online postgres server, so i will finish this with project with the local postgres DB and them make all the necessary changes to move it to an online mysql server, which i have access to from a web hosting plan i am using.
Your solution seems to be using many pgsql commands, that will be quite hard to change to mysql, if possible.
thanks though,
ilias
I started with this project working on a local postgres DB, with ultimate aim to move it online.
But it seems that i cant find a free online postgres server, so i will finish this with project with the local postgres DB and them make all the necessary changes to move it to an online mysql server, which i have access to from a web hosting plan i am using.
Your solution seems to be using many pgsql commands, that will be quite hard to change to mysql, if possible.
thanks though,
ilias
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
Re: combobox datasource
The difficulty of migration to MySQL database depends on the complexity of your solution. However our approach seems to be easy to use for migration to dotConnect for MySQL. You will need to perform the following actions for migration:skarosg3 wrote:Your solution seems to be using many pgsql commands, that will be quite hard to change to mysql, if possible.
1. Replace:
Code: Select all
using Devart.Data.PostgreSql;
Code: Select all
using Devart.Data.MySql;
3. Replace the connection string with a valid connection string for MySQL Server;
4. Correct SQL queries where necessary (for example, if the table names are different).
If you already have a PostgreSQL database, you can use our SSIS functionality for migrating data from PostgreSQL to MySQL. For more information, please refer to
http://www.devart.com/dotconnect/mysql/ ... _SSIS.html
http://www.devart.com/dotconnect/postgr ... _SSIS.html