SIGN UP MEMBER LOGIN:    
ARTICLE

Revise-Generating ComboBox in a DataGrid Column

Posted by Paul Coldrey Articles | Windows Controls C# June 10, 2004
This article and attached source code shows how to add a ComboBox column to a DataGrid control.
Reader Level:
Download Files:
 

Notes

A ColumnStyle to let you have a combobox column in a .NET DataGrid. The URL is the link where I lifted most of the code from. I fixed a couple of things like showing the DisplayMember not the value member when the item doesn't have focus + I made it so if you select something from the combo box then it makes that row of the DataGrid commit even if no other changes are made.


Associated URL
http://www.c-sharpcorner.com/winforms/ComboBoxInDataGridSKJ.asp

Login to add your contents and source code to this article
share this article :
post comment
 

I have some question ,i don't know how to do it .
i have three table in my database access :
-attendees
-events
-registration
there is a combox what is represented for companyName in attendees table
i had a form what is written by c# when i select companyName in combox ,it will display some information that relevant to this company name, in this part i did it,but  i have also a datagridview  ,and i need when i click on combox it not only display as i said before but also display some information of event of this company ,so i try to do many way but in this part i can't .the Error said that "Data type mismatch in criteria expression." this is  my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace project2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
          
            OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\dquang\\Desktop\\project2.mdb");
            con.Open();
            OleDbDataAdapter adap = new OleDbDataAdapter("select * from Attendees", con);
            DataSet ds=new DataSet();
             adap.Fill(ds);
             comboBox1.DataSource = ds.Tables[0];
             comboBox1.DisplayMember = "CompanyName";
             comboBox1.ValueMember = "CompanyName";


        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string company = comboBox1.SelectedValue.ToString();
            OleDbConnection con1 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\dquang\\Desktop\\project2.mdb");
            con1.Open();
            OleDbDataAdapter adap1 = new OleDbDataAdapter("select * from Attendees where CompanyName='" + company + "'", con1);
            DataSet ds1 = new DataSet();
            //adap1.Fill(ds1);
            adap1.Fill(ds1, "Attendees");
            DataTable dt = new DataTable();
            dt = ds1.Tables["Attendees"];

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];
                lattendeeID.Text = row["AttendeeID"].ToString();
                txtAddress.Text = row["Address"].ToString();
                txtCity.Text = row["City"].ToString();
                txtStateProvince.Text = row["StateOrProvince"].ToString();
                txtPostalcode.Text = row["PostalCode"].ToString();
                txtCountry.Text = row["Country"].ToString();
                txtFirstName.Text = row["AttendeeFirstName"].ToString();
                txtLastName.Text = row["AttendeeLastName"].ToString();
                txtTitle.Text = row["title"].ToString();
                txtPhone.Text = row["PhoneNumber"].ToString();
                txtFax.Text = row["FaxNumber"].ToString();
                txtNotes.Text = row["Notes"].ToString();
            }

            string sql = "select EventName,StartDate,SalesTaxRate from Events,Registration where AttendeeID='" + lattendeeID.Text + "'";
            OleDbConnection con2 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\dquang\\Desktop\\project2.mdb");
            con2.Open();
            OleDbDataAdapter adap3 = new OleDbDataAdapter(sql, con2);
            DataSet ds3 = new DataSet();
            adap3.Fill(ds3);=======error (i don't know how to handle,please help me)
            gridviewEvent.DataSource = ds3.Tables[0];

Posted by duyquang le Mar 14, 2010
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Gauge for SharePoint
Become a Sponsor