Get the underlying combo of a datagridviewcomboboxcolumn
-
Hello I'm trying to acceed the combobox property of a datagridview combobox column I can do it using the EditingControlShowing event
// \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* private void DgvKeys\_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if (noEvent) { return; } ComboBox combo = e.Control as ComboBox; }
But I need to acceed directly any combo in some column without having to waint an event on it ! To set the combo selected intex for example I was trying this but it does not work !
DataGridViewComboBoxColumn cby; cby = (DataGridViewComboBoxColumn)DgvKeys.Columns\["Region"\]; cby.SelectedIndex = cby.FindStringExact(combo.Text);
Any idea ?
-
Hello I'm trying to acceed the combobox property of a datagridview combobox column I can do it using the EditingControlShowing event
// \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* private void DgvKeys\_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if (noEvent) { return; } ComboBox combo = e.Control as ComboBox; }
But I need to acceed directly any combo in some column without having to waint an event on it ! To set the combo selected intex for example I was trying this but it does not work !
DataGridViewComboBoxColumn cby; cby = (DataGridViewComboBoxColumn)DgvKeys.Columns\["Region"\]; cby.SelectedIndex = cby.FindStringExact(combo.Text);
Any idea ?
baranils wrote:
I was trying this but it does not work !
Can you describe in more detail the circumstances when you would want to do this?
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
baranils wrote:
I was trying this but it does not work !
Can you describe in more detail the circumstances when you would want to do this?
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
Thank you Henry "Can you describe in more detail the circumstances when you would want to do this?" Good question ! I have three combobox column on single row (one and only one) Those three combo are binded to three different tables There is a logical relation berween those tables If the user select a value in the third combo I want to show the related value in the first and second cell So I'm trying to force the values of two cell but it doesn't work I'm trying this If I change the appellation Column Pays must shows "France" And Region must Show "Bordeaux" But Pays remain empty !! I thought it was because I also have to change the selected item of the combo ??
// \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* private void DgvKeys\_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if (noEvent) { return; } ComboBox combo = e.Control as ComboBox; if (combo != null) { combo.DropDownStyle = ComboBoxStyle.DropDown; combo.AutoCompleteMode = AutoCompleteMode.SuggestAppend; combo.AutoCompleteSource = AutoCompleteSource.ListItems; combo.SelectedIndexChanged -= new EventHandler(ComboBox\_SelectedIndexChanged); combo.SelectedIndexChanged += new EventHandler(ComboBox\_SelectedIndexChanged); } } // \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* private void ComboBox\_SelectedIndexChanged(object sender, EventArgs e) { noEvent = true; ComboBox combo = (ComboBox)sender; if (combo.SelectedItem == null) { return; } DataRowView cRowV = (DataRowView)combo.SelectedItem; DataRow cRow = cRowV.Row; if (combo.DisplayMember == "Appellation") { DgvKeys.Rows\[0\].Cells\["Pays"\].Value = "France"; // = GetPaysName(cRow\["PaysID"\]); DgvKeys.Rows\[0\].Cells\["Region"\].Value = "Bordeaux"; // GetRegionName(cRow\["RegionID"\]); curApel = cRow\["Appellation"\].ToString(); curApelID = Tools.GetInt(cRow\["ApelID"\]); noEvent = false; return; } }
-
Thank you Henry "Can you describe in more detail the circumstances when you would want to do this?" Good question ! I have three combobox column on single row (one and only one) Those three combo are binded to three different tables There is a logical relation berween those tables If the user select a value in the third combo I want to show the related value in the first and second cell So I'm trying to force the values of two cell but it doesn't work I'm trying this If I change the appellation Column Pays must shows "France" And Region must Show "Bordeaux" But Pays remain empty !! I thought it was because I also have to change the selected item of the combo ??
// \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* private void DgvKeys\_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if (noEvent) { return; } ComboBox combo = e.Control as ComboBox; if (combo != null) { combo.DropDownStyle = ComboBoxStyle.DropDown; combo.AutoCompleteMode = AutoCompleteMode.SuggestAppend; combo.AutoCompleteSource = AutoCompleteSource.ListItems; combo.SelectedIndexChanged -= new EventHandler(ComboBox\_SelectedIndexChanged); combo.SelectedIndexChanged += new EventHandler(ComboBox\_SelectedIndexChanged); } } // \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* private void ComboBox\_SelectedIndexChanged(object sender, EventArgs e) { noEvent = true; ComboBox combo = (ComboBox)sender; if (combo.SelectedItem == null) { return; } DataRowView cRowV = (DataRowView)combo.SelectedItem; DataRow cRow = cRowV.Row; if (combo.DisplayMember == "Appellation") { DgvKeys.Rows\[0\].Cells\["Pays"\].Value = "France"; // = GetPaysName(cRow\["PaysID"\]); DgvKeys.Rows\[0\].Cells\["Region"\].Value = "Bordeaux"; // GetRegionName(cRow\["RegionID"\]); curApel = cRow\["Appellation"\].ToString(); curApelID = Tools.GetInt(cRow\["ApelID"\]); noEvent = false; return; } }