Click here to Skip to main content
15,889,281 members
Home / Discussions / C#
   

C#

 
AnswerRe: when using Stored Procedure called from C# ? Pin
ZurdoDev21-Jun-14 15:38
professionalZurdoDev21-Jun-14 15:38 
GeneralRe: when using Stored Procedure called from C# ? Pin
Member 245846722-Jun-14 18:28
Member 245846722-Jun-14 18:28 
QuestionRectangleToScreen on a WinForm Bounding Box gives strange co-ordinates ? Pin
BillWoodruff19-Jun-14 14:39
professionalBillWoodruff19-Jun-14 14:39 
AnswerRe: RectangleToScreen on a WinForm Bounding Box gives strange co-ordinates ? Pin
OriginalGriff19-Jun-14 21:14
mveOriginalGriff19-Jun-14 21:14 
GeneralRe: RectangleToScreen on a WinForm Bounding Box gives strange co-ordinates ? Pin
BillWoodruff19-Jun-14 23:28
professionalBillWoodruff19-Jun-14 23:28 
GeneralRe: RectangleToScreen on a WinForm Bounding Box gives strange co-ordinates ? Pin
OriginalGriff19-Jun-14 23:37
mveOriginalGriff19-Jun-14 23:37 
QuestionRe: RectangleToScreen on a WinForm Bounding Box gives strange co-ordinates ? Pin
Richard MacCutchan20-Jun-14 1:33
mveRichard MacCutchan20-Jun-14 1:33 
QuestionBinding two ComboBoxes Pin
sbn101019-Jun-14 9:18
sbn101019-Jun-14 9:18 
hi all people
i have a windows form that containes two ComboBoxes, two DataGrids and TextBoxes, i made the necessary to bind all the controls except the second ComboBox (That depends on what is selected in the first ComboBox ), infact i filled the first ComboBox cbCust with the table Customers and i want the second ComboBox cbOrd to be filled with the Orders of the selected Customer. my hole Code is :
C#
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;

namespace DataBinding
{
	// Shows Master-Detail, Table-Mapping, Fill a Combobox
	public class MasterDetail : System.Windows.Forms.Form
	{
		private System.Windows.Forms.DataGrid grdOrders;
		private System.Windows.Forms.DataGrid grdOrderDetails;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.ComboBox cbCust;
		private System.Windows.Forms.TextBox txtPhoneNo;
		private System.Windows.Forms.TextBox txtFaxNo;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TextBox txtContact;
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox2;
        private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.Button btnPrev;
		private System.Windows.Forms.Button btnNext;

		// My privates
		//private String ConnectionString;
		//private DataViewManager dsView;
		//private DataSet ds;



        OleDbConnection cn;
        DataSet ds;
        private Label label5;
        private ComboBox cbOrd;
        DataViewManager dsView;

		public MasterDetail()
		{
			// Create Components
			InitializeComponent();

			// Setup DB-Connection
			cn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\DataBinding\Northwind.accdb;Persist Security Info=False");
			

			// Create the DataSet      
			ds = new DataSet("CustOrders");

			// Fill the Dataset with Customers, map Default Tablename
			// "Table" to "Customers".
            OleDbDataAdapter da1 = new OleDbDataAdapter("SELECT * FROM Customers", cn);
			da1.TableMappings.Add("Table","Customers");
			da1.Fill(ds);
			
			// Fill the Dataset with Orders, map Default Tablename
			// "Table" to "Orders".			
            OleDbDataAdapter da2 = new OleDbDataAdapter("SELECT * FROM Orders", cn);
			da2.TableMappings.Add("Table","Orders");
			da2.Fill(ds);

			// Fill the Dataset with [Order Details], map Default Tablename
			// "Table" to "OrderDetails".			
            OleDbDataAdapter da3 = new OleDbDataAdapter("SELECT * FROM [Order Details]", cn);
			da3.TableMappings.Add("Table","OrderDetails");
			da3.Fill(ds);

			
			// Establish the Relationship "RelCustOrd" 
			// between Customers ---< Orders
			System.Data.DataRelation relCustOrd;
			System.Data.DataColumn  colMaster1;
			System.Data.DataColumn  colDetail1;
			colMaster1 = ds.Tables["Customers"].Columns["CustomerID"];
			colDetail1 = ds.Tables["Orders"].Columns["CustomerID"];
			relCustOrd = new System.Data.DataRelation("RelCustOrd",colMaster1,colDetail1);
			ds.Relations.Add(relCustOrd);


			// Establish the Relationship "RelOrdDet" 
			// between Orders ---< [Order Details]
			System.Data.DataRelation relOrdDet;
			System.Data.DataColumn  colMaster2;
			System.Data.DataColumn  colDetail2;
			colMaster2 = ds.Tables["Orders"].Columns["OrderID"];
			colDetail2 = ds.Tables["OrderDetails"].Columns["OrderID"];
			relOrdDet = new System.Data.DataRelation("RelOrdDet",colMaster2,colDetail2);
			ds.Relations.Add(relOrdDet);
 
			

			
			dsView = ds.DefaultViewManager;

			// Databinding for the Grid's
			grdOrders.DataSource = dsView;
			grdOrders.DataMember = "Customers.RelCustOrd";

			grdOrderDetails.DataSource = dsView;
			grdOrderDetails.DataMember = "Customers.RelCustOrd.RelOrdDet";
      
			
            // Databinding for the Combo Box
			
			cbCust.BindingContext = new BindingContext(); 
			cbCust.DataSource = dsView;
			cbCust.DisplayMember = "Customers.CompanyName";
            cbCust.ValueMember = "Customers.CustomerID";


            cbOrd.DataSource = dsView;
            cbOrd.DisplayMember = "Customers.RelCustOrd";
            cbOrd.ValueMember = "Orders.OrderID";


			// Databinding for the Text Columns
			txtContact.DataBindings.Add("Text",dsView,"Customers.ContactName");
			txtPhoneNo.DataBindings.Add("Text",dsView,"Customers.Phone");
			txtFaxNo.DataBindings.Add("Text",dsView,"Customers.Fax");
		}
	
		// Position to prev Record in Customer
		private void btnPrev_Click(object sender, System.EventArgs e)
		{
			if (this.BindingContext[dsView,"Customers"].Position > 0) 
			{
				this.BindingContext[dsView,"Customers"].Position--;
			}
		}

		// Position to next Record in Customer
		private void btnNext_Click(object sender, System.EventArgs e)
		{
			CurrencyManager cm = (CurrencyManager)this.BindingContext[dsView,"Customers"];
			if (cm.Position < cm.Count - 1) 
			{
				cm.Position++;
			}
		}

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

my question is : How to do to fill the cbOrd ComboBox using the DataBinding?
Thanks in advance.

modified 19-Jun-14 15:31pm.

AnswerRe: Binding two ComboBoxes Pin
Eddy Vluggen20-Jun-14 8:06
professionalEddy Vluggen20-Jun-14 8:06 
Questionextract data from excel Pin
solo919-Jun-14 8:37
solo919-Jun-14 8:37 
AnswerRe: extract data from excel Pin
Richard Deeming19-Jun-14 8:54
mveRichard Deeming19-Jun-14 8:54 
AnswerRe: extract data from excel Pin
CatchExAs19-Jun-14 12:31
professionalCatchExAs19-Jun-14 12:31 
AnswerRe: extract data from excel Pin
Richard MacCutchan19-Jun-14 22:53
mveRichard MacCutchan19-Jun-14 22:53 
QuestionChange Properties Category during runtime for PropertyGrid Pin
Mc_Topaz19-Jun-14 4:12
Mc_Topaz19-Jun-14 4:12 
AnswerRe: Change Properties Category during runtime for PropertyGrid Pin
Bernhard Hiller19-Jun-14 20:49
Bernhard Hiller19-Jun-14 20:49 
RantRe: Change Properties Category during runtime for PropertyGrid Pin
Mc_Topaz19-Jun-14 21:17
Mc_Topaz19-Jun-14 21:17 
RantRe: Change Properties Category during runtime for PropertyGrid Pin
Eddy Vluggen20-Jun-14 8:22
professionalEddy Vluggen20-Jun-14 8:22 
QuestionNon-XML ini-file supporting arrays, in plain text format? Pin
arnold_w19-Jun-14 3:30
arnold_w19-Jun-14 3:30 
AnswerRe: Non-XML ini-file supporting arrays, in plain text format? Pin
V.19-Jun-14 4:07
professionalV.19-Jun-14 4:07 
GeneralRe: Non-XML ini-file supporting arrays, in plain text format? Pin
arnold_w19-Jun-14 5:07
arnold_w19-Jun-14 5:07 
GeneralRe: Non-XML ini-file supporting arrays, in plain text format? Pin
Eddy Vluggen19-Jun-14 5:13
professionalEddy Vluggen19-Jun-14 5:13 
GeneralRe: Non-XML ini-file supporting arrays, in plain text format? Pin
Dave Kreskowiak19-Jun-14 5:52
mveDave Kreskowiak19-Jun-14 5:52 
GeneralRe: Non-XML ini-file supporting arrays, in plain text format? Pin
arnold_w19-Jun-14 21:41
arnold_w19-Jun-14 21:41 
GeneralRe: Non-XML ini-file supporting arrays, in plain text format? Pin
V.19-Jun-14 21:44
professionalV.19-Jun-14 21:44 
GeneralRe: Non-XML ini-file supporting arrays, in plain text format? Pin
arnold_w19-Jun-14 21:47
arnold_w19-Jun-14 21:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.