This is using table
DailyQA (ID, TransDate, Station, QAEmplID) Employee (EmplID,Name)
There is DateTimePicker and StationCombobox on the form.
When select Date and Station, QANameCombobox(DailyQA.QAEmplID) will be changed by selected values.
First IfindDailyQA.IDfrom Date and Station then display name of QAEmplID in QANameCombobox.
(select Name from Employee.EmplIDwhere EmplID = DailyQA.QAEmplID )
AndI'd like todropdown QANameCombobox to change another QAName also.(list all Employee.Name)
But I dont know how to bind combobox.
This is my code....
string sql = "SELECT EmplID ,Name FROM Employee";
System.Data.SqlClient. SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds, "Employee");
QAComboBox.DataSource = ds.Tables[ "zEmployee"].DefaultView;
QAComboBox.DisplayMember = "Name";
QAComboBox.ValueMember = "EmplId";
//QAComboBox.DataBindings.Add("SelectedValue", **DailyQA.QAEmplID**, "QAID"); how to code here??
Thanks in advance.
Robin
| | Oopz Thursday, November 20, 2008 3:06 AM | Hi RobinJung,
Here is the example how to handle the ComboBoxColumn selection change event to modify the datasource.
Code Snippet
Snippe Form1()
new DataGridViewEditingControlShowingEventHandler(dataGridView1_EditingControlShowing);
void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
ComboBox cmb = e.Control as ComboBox;
if (cmb != null)
new EventHandler(cmb_SelectedIndexChanged);
void cmb_SelectedIndexChanged(object sender, EventArgs e)
// For example, 1 is the column index of StationCombobox
if (dataGridView1.CurrentCell.ColumnIndex == 1)
// When the selection of StationCombobox changed
// You can set the under line value of QANameCombobox
// Then the QANameCombobox will change its seletion automatically
Kira Qian | | Kira Qian Tuesday, November 25, 2008 5:10 AM | This is using table
DailyQA (ID, TransDate, Station, QAEmplID) Employee (EmplID,Name)
There is DateTimePicker and StationCombobox on the form.
When select Date and Station, QANameCombobox(DailyQA.QAEmplID) will be changed by selected values.
First IfindDailyQA.IDfrom Date and Station then display name of QAEmplID in QANameCombobox.
(select Name from Employee.EmplIDwhere EmplID = DailyQA.QAEmplID )
AndI'd like todropdown QANameCombobox to change another QAName also.(list all Employee.Name)
But I dont know how to bind combobox.
This is my code....
string sql = "SELECT EmplID ,Name FROM Employee";
System.Data.SqlClient. SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds, "Employee");
QAComboBox.DataSource = ds.Tables[ "zEmployee"].DefaultView;
QAComboBox.DisplayMember = "Name";
QAComboBox.ValueMember = "EmplId";
//QAComboBox.DataBindings.Add("SelectedValue", **DailyQA.QAEmplID**, "QAID"); how to code here??
Thanks in advance.
Robin
| | Oopz Thursday, November 20, 2008 3:09 AM |
Hi RobinJung,
You can bind Text property of combobox.
Code Snippet
QAComboBox.DataBindings.Add( New Binding("Text", _BindingCollection, "QAID"))
Change _BindingCollection as per your code.
And make sure, before binding, Combobox is having data.
If still problem let me know.
Thank you
Best Regards
Utkarsh Gajjar. | | Utkarsh Thursday, November 20, 2008 2:41 PM | It's error, "This causes two bindings in the collection to bind to the same property. Parameter name: binding"
| | Oopz Friday, November 21, 2008 4:14 AM |
Hi RobinJung
I am sorry to say DataGridViewComboBoxColumn doesn’t support single databind which ComboBox control does. So you need to handle ValueChanged event for example to change the SelectedValue of ComboBoxColumn under the datasource. In order to handle the event of the contorl in the DataGridViewCell, you can use EditingControlShowing to show the control and handle the event.
If you have any question, please feel free to tell me.
Sincerely,
Kira Qian | | Kira Qian Monday, November 24, 2008 3:35 AM | Thanks a lot Kia for your reply.
I'm a newbie in .net >_<" Idont haveidea that you told me.
Could you please show me coding example?
Best Regards.
Robin
| | Oopz Monday, November 24, 2008 6:57 PM | Hi RobinJung,
Here is the example how to handle the ComboBoxColumn selection change event to modify the datasource.
Code Snippet
Snippe Form1()
new DataGridViewEditingControlShowingEventHandler(dataGridView1_EditingControlShowing);
void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
ComboBox cmb = e.Control as ComboBox;
if (cmb != null)
new EventHandler(cmb_SelectedIndexChanged);
void cmb_SelectedIndexChanged(object sender, EventArgs e)
// For example, 1 is the column index of StationCombobox
if (dataGridView1.CurrentCell.ColumnIndex == 1)
// When the selection of StationCombobox changed
// You can set the under line value of QANameCombobox
// Then the QANameCombobox will change its seletion automatically
Kira Qian | | Kira Qian Tuesday, November 25, 2008 5:10 AM | Hi Robin
Please explain me in clear , I cant understand your point where you need assistants
thanks & regards Dhinesh paramasivam
| | iyngarangce Tuesday, November 25, 2008 5:57 AM |
|