In a prior application, I had 2 combo boxes linked. So if they chose something from CB1 it selected the match in CB2. I did this by selected index because both lists were in the same order.
I now want to do something similar but I want the order to be different now. I want each to be alphabatized. So using selected index obviously won't work. For the life of me I can't get this to work. From what I understand if I am making CB2 match CB1 (cause they changed CB1), I need to set CB2.SelectedValue and I tried that. But I'm just confused. SelecteText really doesn't have a value anymore. so how can I accomplish this? Thank you in advance before I turn grey! LOL
private void cbSupervisor_SelectionChangeCommitted(object sender, EventArgs e)
{ cbSupervisorName.SelectedValue = cbSupervisor.SelectedText; }
private void cbSupervisorName_SelectionChangeCommitted(object sender, EventArgs e){ cbSupervisor.SelectedValue = cbSupervisorName.SelectedText; }
Lisa MPosted Apr 28, 2009, 3:38 PM
BINGO! Thank you! I changed it to a dropdownlist and now it works!
Thank you so much!
Kumar AGPosted Apr 28, 2009, 1:56 PM
You are not using correct property
Ok here is the description for the Selected Text property in MSDN
A string that represents the currently selected text in the combo box. If DropDownStyle is set to DropDownList, the return value is an empty string ("").
You can assign text to this property to highlight specified text or change only the currently selected text in the ComboBox. If no text is currently selected in the ComboBox, this property returns a zero-length string.
Lisa MPosted Apr 28, 2009, 1:29 PM
For the record, if I do the first line, SelectedValue is blank when I try to grab it later when a button is pushed. If I do it the 2nd way, I get a value in SelectedValue. Why the heck is that?
cbSupervisor.SelectedText = cbSupervisorName.SelectedValue.ToString();cbSupervisor.SelectedIndex = cbSupervisorName.SelectedIndex;
Lisa MPosted Apr 28, 2009, 1:25 PM
Kumar AGPosted Apr 28, 2009, 1:10 PM
{
comboBox2.Text = (
string)comboBox1.SelectedValue;}
private void comboBox2_SelectionChangeCommitted(object sender, EventArgs e){
comboBox1.SelectedValue = comboBox2.Text;
}
Lisa MPosted Apr 28, 2009, 11:35 AM
CB1.DisplayMember = "SupCode"
CB1.ValueMember = "SupName"
CB2.DisplayMember = "SupName"
CB2.ValueMember = "SupCode"
When they change CB1, I can successfully do
CB2.SelectedText = CB1.SelectedValue.ToString();
to switch CB2 to show the name for the code selected in CB1. The problem is later when they save the data on the form, I need the value of each combobox. Because they physically selected the item in CB1, I can use SelectedValue just fine. But it appears becasue CB2 was programmatically set, there is no actual selected item. So CB2.SelectedValue, CB2SelectedText, CB2.SelectedItem, they are all null or blank.
Kumar AGPosted Apr 28, 2009, 11:10 AM
Try this
private void cbSupervisor_SelectionChangeCommitted(object sender, EventArgs e)
{ cbSupervisorName.SelectedValue = cbSupervisor.SelectedValue; }
private void cbSupervisorName_SelectionChangeCommitted(object sender, EventArgs e)
{ cbSupervisor.SelectedValue = cbSupervisorName.SelectedValue; }
Lisa MPosted Apr 28, 2009, 10:05 AM
"System.Data.DataRowView"
And it does not work.
Vimal KandasamyPosted Apr 28, 2009, 12:11 AM
try this,
{{