LoginSignup
0

More than 1 year has passed since last update.

.NET Framework 4.XではCheckedListBoxからVB6.Support.GetItemStringで値が取得できない

Last updated at Posted at 2021-12-05

概要

検証結果

x86(32bitアプリケーション)、NetFx 3.5 および 4.7.2 でのみ確認しています。

プラットフォーム コントロール フレームワーク 値取得
x86 ListBox NetFx 3.5 OK
x86 CheckedListBox NetFx 3.5 OK
x86 ListBox NetFx 4.7.2 OK
x86 CheckedListBox NetFx 4.7.2 NG

Microsoft.VisualBasic.Compatibility.VB6 は、4.7.2では、32bitアプリケーションしかサポートされていません。言い換えると、32bitアプリケーションはサポート対象ですが、32bitアプリケーションでも動作が変更となっていました。

詳細(再現)

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ListBox1.Items.Add("a")
        ListBox1.Items.Add("bb")
        ListBox1.Items.Add("ccc")
        CheckedListBox1.Items.Add("a")
        CheckedListBox1.Items.Add("bb")
        CheckedListBox1.Items.Add("ccc")
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        MsgBox(Microsoft.VisualBasic.Compatibility.VB6.GetItemString(ListBox1, 0))
        MsgBox(Microsoft.VisualBasic.Compatibility.VB6.GetItemString(CheckedListBox1, 0))
    End Sub
End Class

対処

次のように変更する

変更前

VB6.GetItemString(ListBox1, 0)

変更後

ListBox1.Items(0).ToString

IDEでの正規表現例

変更前後で十分にご確認ください。

検索: (VB6.GetItemString\()([^,]+)(, )([^\)]+)(\))
置換: $2.Items($4).ToString

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0