Help and Support
 

powered byLive Search

[BUG]: Text プロパティ データ バインド コンボ ボックス (ComboBox) コントロールの返されます誤った値がコード内の値を設定するときに

文書番号:327555
最終更新日:2007年5月11日
リビジョン:3.5
目次

現象

if programmatically the ComboBox control of a data-bound member for the Text property set, expected as the value in the ComboBox of the text box portion typed is displayed. however, Text property the and the SelectedIndex property incorrectly return value in the value in the text box typed returning instead of the list box selected was that the last item of the.

when type in the ComboBox runtime at, Text property returns the typed value, and SelectedIndex returns a value -1 of.

先頭へ戻る

解決方法

この問題を解決するには、 コンボ ボックス (ComboBox) コントロール 、次の例のようにのデータ バインド メンバの Text プロパティを設定する前に、 SelectedIndex プロパティを -1 に設定します。

Visual Basic .NET

ComboBox1.SelectedIndex = -1
ComboBox1.Text = "My Text"
				

Visual C# .NET

ComboBox1.SelectedIndex = -1;
ComboBox1.Text = "My Text";
				
NOTE : Do to the ComboBox of a data-bound member select the Text property use not. must want to show, that the list in the item locate and the index of the item to set the SelectedIndex then. to set the Text property have not do.

for example, a list to the DisplayMember property and the ComboBox of the ValueMember property bind if that contains the numbers through 10, 1 and want to the text box in the number 5 display and the SelectedIndex property 5 to set must 5 in the list, selected as show the ComboBox.

先頭へ戻る

状況

Microsoft はこのとして認識していますバグ、Microsoft にこの資料の冒頭に記載した製品です。

先頭へ戻る

詳細

動作を再現する手順

1.create a new Visual Basic .NET or Visual Basic 2005 Windows application.

既定では、Form1 が作成されます。
2.an \fbox command add, add a TextBox control, and then Form1 to a Button control add.
3.Form1 on a Code window を open.
4.the Code window the Windows Form Designer Generated Code section below into the following code paste:
    Private Sub Form1_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load
        ' Create a DataTable on which to bind the ComboBox.
        Dim myDT As New DataTable()

        Dim myCOL1 As DataColumn = New DataColumn()
        Dim myCOL2 As DataColumn = New DataColumn()

        myCOL1.ColumnName = "ContactName"
        myCOL2.ColumnName = "ContactID"

        myCOL1.DataType = System.Type.GetType("System.String")
        myCOL2.DataType = System.Type.GetType("System.Int32")

        myDT.Columns.Add(myCOL1)
        myDT.Columns.Add(myCOL2)

        ' Populate the DataTable.
        Dim myDR As DataRow

        myDR = myDT.NewRow
        myDR.Item(0) = "North"
        myDR.Item(1) = 0
        myDT.Rows.Add(myDR)

        myDR = myDT.NewRow()
        myDR.Item(0) = "South"
        myDR.Item(1) = 1
        myDT.Rows.Add(myDR)

        myDR = myDT.NewRow()
        myDR.Item(0) = "East"
        myDR.Item(1) = 2
        myDT.Rows.Add(myDR)

        ' Bind the ComboBox.
        ComboBox1.DataSource = myDT
        ComboBox1.DisplayMember = "ContactName"
        ComboBox1.ValueMember = "ContactID"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles Button1.Click
        ComboBox1.Text = "Hello!"
        MessageBox.Show(ComboBox1.Text)
    End Sub
					
Note change the code in Visual Basic 2005 must. Visual Basic by default, a Windows Forms project create when the project for two files creates. Form1 named is the form, if the form represent that the two files Form1.vb and Form1.Designer.vb are named. Form1.vb the file in the code を write. Windows フォーム デザイナのコードを Form1.Designer.vb ファイルに書き込みます。 Windows フォーム デザイナは、部分的なキーワード使用して Form1 の実装を 2 つの個別のファイルに分割します。 この現象は、デザイナで生成したコード、コードに混入されるできなくなります。

for more information about the new Visual Basic 2005 language enhancements, the following MSDN (Microsoft Developer Network) Web site visit:
http://msdn2.microsoft.com/en-us/library/ms379584(vs.80).aspx (http://msdn2.microsoft.com/en-us/library/ms379584(vs.80).aspx)
for more information about partial classes and the Windows Forms Designer, the following MSDN Web site visit:
http://msdn2.microsoft.com/en-us/library/ms171843.aspx (http://msdn2.microsoft.com/en-us/library/ms171843.aspx)
5.run the application, and then the Button control click.

Text プロパティ値は返されるは、 コンボ ボックス (ComboBox) コントロール 、選択した項目と同じですおりされませんプログラムによって設定された値に等しいします。

先頭へ戻る


この資料は以下の製品について記述したものです。
?Microsoft .NET Framework 1.1
?Microsoft Visual Basic 2005 Express Edition
?Microsoft Visual Basic .NET 2003 Standard Edition
?Microsoft Visual Basic .NET 2002 Standard Edition
?Microsoft Visual C# 2005 Express Edition
?Microsoft Visual C# .NET 2003 Standard Edition
?Microsoft Visual C# .NET 2002 Standard Edition

先頭へ戻る

キーワード:?
kbmt kbvs2005applies kbvs2005swept kbvs2002sp1sweep kbbug KB327555 KbMtja

先頭へ戻る

機械翻訳重要: このサポート技術情報 (以下「KB」) は、翻訳者による翻訳の代わりに、マイクロソフト機械翻訳システムによって翻訳されたものです。マイクロソフトは、お客様に、マイクロソフトが提供している全ての KB を日本語でご利用いただけるように、翻訳者による翻訳 KB に加え機械翻訳 KB も提供しています。しかしながら、機械翻訳の品質は翻訳者による翻訳ほど十分ではありません。誤訳や、文法、言葉使い、その他、たとえば日本語を母国語としない方が日本語を話すときに間違えるようなミスを含んでいる可能性があります。マイクロソフトは、機械翻訳の品質、及び KB の内容の誤訳やお客様が KB を利用されたことによって生じた直接または間接的な問題や損害については、いかなる責任も負わないものとします。マイクロソフトは、機械翻訳システムの改善を継続的に行っています。もし誤訳を発見された場合には、この KB 下部よりフィードバックをお寄せください。
英語版 KB:327555 (http://support.microsoft.com/kb/327555/en-us/)

先頭へ戻る

"Microsoft Knowledge Baseに含まれている情報は、いかなる保証もない現状ベースで提供されるものです。Microsoft Corporation及びその関連会社は、市場性および特定の目的への適合性を含めて、明示的にも黙示的にも、一切の保証をいたしません。さらに、Microsoft Corporation及びその関連会社は、本文書に含まれている情報の使用及び使用結果につき、正確性、真実性等、いかなる表明・保証も行ないません。Microsoft Corporation、その関連会社及びこれらの権限ある代理人による口頭または書面による一切の情報提供またはアドバイスは、保証を意味するものではなく、かつ上記免責条項の範囲を狭めるものではありません。Microsoft Corporation、その関連会社 及びこれらの者の供給者は、直接的、間接的、偶発的、結果的損害、逸失利益、懲罰的損害、または特別損害を含む全ての損害に対して、状況のいかんを問わず一切責任を負いません。(Microsoft Corporation、その関連会社 またはこれらの者の供給者がかかる損害の発生可能性を了知している場合を含みます。) 結果的損害または偶発的損害に対する責任の免除または制限を認めていない地域においては、上記制限が適用されない場合があります。なお、本文書においては、文書の体裁上の都合により製品名の表記において商標登録表示、その他の商標表示を省略している場合がありますので、予めご了解ください。"

サポート技術情報の翻訳

 

Other Support Options

  • Need More Help?
    Contact a Support professional by Email, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.