2016-04-25 43 views
0

我不能编辑文本框中的文本。我需要文本框在开始时显示文本,然后才能进行编辑。 imageName显示在文本框中,但我不能编辑它到别的东西。如何在使用Text box.text设置的文本框中编辑文本?

private void image_NameTextBox_TextChanged(object sender, EventArgs e) 
    { 
     string imageName = (dictionaryDataSet1.Tables[0].Rows[selectedIndex]["Image Name"].ToString()); 

     image_NameTextBox.Text = imageName; 
    } 

回答

0

看起来像你为TextBox定义了一个TextChanged-Event。每当您编辑文本时,您都会打电话给您的处理程序:

private void image_NameTextBox_TextChanged(object sender, EventArgs e) 
    { 
     string imageName = (dictionaryDataSet1.Tables[0].Rows[selectedIndex]["Image Name"].ToString()); 

     image_NameTextBox.Text = imageName; 
    } 

结果是:您正在将文本设置回旧值。

从您的文本框中移除该事件并以不同的方法填充您的文本。

0

您在TextChanged事件中拥有您的代码,这意味着您每次尝试编辑文本时都会将其设置回相同的事件。将您的代码移到TextChanged事件之外(它仍然可以正常工作),然后尝试编辑您的文本。