Soft009 wrote:
I have datagrid view and in it datagridcombobox column.
i really didnt get this part
Soft009 wrote:
I want to bind data to that datagrid combo box column
but i did understand a bit here, u mean u wana bind data to the combobox right well then her's something for ya
explanation: what i have in this code is a combobox and gridview if i select a particular field from my combobox then all the data related to that particular field will be fetched up and will be shown in the datagrid
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.SqlClient;
namespace Record_Holder
{
public partial class InquiryDetails : Form
{
public InquiryDetails()
{
InitializeComponent();
}
private void InquiryDetails_Load(object sender, EventArgs e)
{
dataGridView1.Visible = false;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=.;Initial Catalog=RJIT;Integrated Security=True";
conn.Open();
string command = "select distinct time_of_inquiry from Inquiry_Table";
SqlCommand cmd = new SqlCommand(command, conn);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read() == true)
{
comboBox1.Items.Add(dr[0].ToString());
}
conn.Close();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
int x=0;
SqlConnection connect = new SqlConnection();
connect.ConnectionString = "Data Source=.;Initial Catalog=RJIT;Integrated Security=True";
connect.Open();
string mycommand = "select * from Inquiry_Table where time_of_inquiry='" + comboBox1.Text + "'";
SqlCommand cmd = new SqlCommand(mycommand, connect);
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = cmd;
DataSet ds = new DataSet();
DataTable dt;
adp.Fill(ds);
dt = ds.Tables[0];
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read() == true)
{
dataGridView1.Visible = true;
dataGridView1.DataSource = dt;
x = x + 1;
}
MessageBox.Show("Total Inquiry found " + x.ToString(),"Information",MessageBoxButtons.OK,MessageBoxIcon.Information);
connect.Close();
}
}
}
Do rate my answer once you find it useful
Thanks & Regards
Radix :rose: