Chnging a combo box entry
-
I have been trying to change an entry in a combo box for a while now and have got the text to change but when i click out of do something else it hasnt actually changed the entries value in the list.
case (char)Keys.Enter: comboBox1.Text.Remove(0, comboBox1.Text.Length); imageViewer1.RenameShape("test"); comboBox1.SelectedText = "test"; comboBox1.Refresh(); break;
Above is my current attempt which changes the text but does not store this change. So my shape renames but the shapes name in the combo box does not. Cant help feeling i need to do more than :
comboBox1.SelectedText = "test";
thanx in advance
-
I have been trying to change an entry in a combo box for a while now and have got the text to change but when i click out of do something else it hasnt actually changed the entries value in the list.
case (char)Keys.Enter: comboBox1.Text.Remove(0, comboBox1.Text.Length); imageViewer1.RenameShape("test"); comboBox1.SelectedText = "test"; comboBox1.Refresh(); break;
Above is my current attempt which changes the text but does not store this change. So my shape renames but the shapes name in the combo box does not. Cant help feeling i need to do more than :
comboBox1.SelectedText = "test";
thanx in advance
Have you tried setting the selected index ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
I have been trying to change an entry in a combo box for a while now and have got the text to change but when i click out of do something else it hasnt actually changed the entries value in the list.
case (char)Keys.Enter: comboBox1.Text.Remove(0, comboBox1.Text.Length); imageViewer1.RenameShape("test"); comboBox1.SelectedText = "test"; comboBox1.Refresh(); break;
Above is my current attempt which changes the text but does not store this change. So my shape renames but the shapes name in the combo box does not. Cant help feeling i need to do more than :
comboBox1.SelectedText = "test";
thanx in advance
Set the
Text
property, not theSelectedText
.SelectedText
is the string within the displayed text that is currently highlighted for cut/copy/paste actions. Setting theText
property will automatically select the correct item in the combo box if it is present. There is also no need to callRefresh
.If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
-
Set the
Text
property, not theSelectedText
.SelectedText
is the string within the displayed text that is currently highlighted for cut/copy/paste actions. Setting theText
property will automatically select the correct item in the combo box if it is present. There is also no need to callRefresh
.If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
Thanx have tried this and the text does change but when i drop down the list test is not there.
case (char)Keys.Enter:
comboBox1.Text.Remove(0, comboBox1.Text.Length);
imageViewer1.RenameShape("test");
comboBox1.Text = "test";
break;It just displays shape1 , shape2 .........
-
Have you tried setting the selected index ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
I have been trying to change an entry in a combo box for a while now and have got the text to change but when i click out of do something else it hasnt actually changed the entries value in the list.
case (char)Keys.Enter: comboBox1.Text.Remove(0, comboBox1.Text.Length); imageViewer1.RenameShape("test"); comboBox1.SelectedText = "test"; comboBox1.Refresh(); break;
Above is my current attempt which changes the text but does not store this change. So my shape renames but the shapes name in the combo box does not. Cant help feeling i need to do more than :
comboBox1.SelectedText = "test";
thanx in advance
-
I have been trying to change an entry in a combo box for a while now and have got the text to change but when i click out of do something else it hasnt actually changed the entries value in the list.
case (char)Keys.Enter: comboBox1.Text.Remove(0, comboBox1.Text.Length); imageViewer1.RenameShape("test"); comboBox1.SelectedText = "test"; comboBox1.Refresh(); break;
Above is my current attempt which changes the text but does not store this change. So my shape renames but the shapes name in the combo box does not. Cant help feeling i need to do more than :
comboBox1.SelectedText = "test";
thanx in advance
I think your problem is that you want to change the value of an entry by typing over it. The problem being that once you start typing you loose any reference to the item you want to change. Perhaps an option would be to handle to OnEnter event and store the selected index, then when you detect the 'Enter' key you can use that index to change the value of the correct item. something like...
int currentIndex = -1;
void OnEnter(object sender, EventArgs e)
{
currentIndex = comboBox1.SelectedIndex;
}void KeyDown(object sender, KeyDownEventArgs e)//or whatever the correct event args is
{
//some code
case (char)Keys.Enter:
imageViewer1.RenameShape("test");
comboBox1.Items[currentIndex] = comboBox1.Text;
comboBox1.Text = "";
break;
}Life goes very fast. Tomorrow, today is already yesterday.
-
I think your problem is that you want to change the value of an entry by typing over it. The problem being that once you start typing you loose any reference to the item you want to change. Perhaps an option would be to handle to OnEnter event and store the selected index, then when you detect the 'Enter' key you can use that index to change the value of the correct item. something like...
int currentIndex = -1;
void OnEnter(object sender, EventArgs e)
{
currentIndex = comboBox1.SelectedIndex;
}void KeyDown(object sender, KeyDownEventArgs e)//or whatever the correct event args is
{
//some code
case (char)Keys.Enter:
imageViewer1.RenameShape("test");
comboBox1.Items[currentIndex] = comboBox1.Text;
comboBox1.Text = "";
break;
}Life goes very fast. Tomorrow, today is already yesterday.
Thank you for all of the replies. I got everything working now there was alot to it as the shapes can be selected by the mouse too so this also had to change the comboBox :
void imageViewer1_Clicked(object sender, EventArgs e)
{
// When shape picked select appropriate entry in the combo box
if (imageViewer1.ListOfShapes.Count > 0)
{
for (int i = 0; i < comboBox1.Items.Count; i++)
{
if ((string)comboBox1.Items[i] == imageViewer1.ListOfShapes[imageViewer1.SelectedShapeIndex].Name) // imageViewer1.ListOfShapes[imageViewer1.SelectedShapeName].Name)
{
comboBox1.SelectedIndex = i;
m_comboBoxCurrentIndex = i;
}
}
}
}Above and below (solution) may not be pretty but it works
case (char)Keys.Enter:
if (comboBox1.SelectedIndex != -1)
{
// Set current selected index and clear text
m_comboBoxCurrentIndex = comboBox1.SelectedIndex;
comboBox1.Text.Remove(0, comboBox1.Text.Length);// Rename shape in image viewer imageViewer1.RenameShape("test"); // Set text for selected item comboBox1.Items\[m\_comboBoxCurrentIndex\] = "test"; comboBox1.Text = ""; }
Thanx George