teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

文字の追加

2019/02/21 15:03

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -120,6 +120,8 @@
120
120
  TextBox1.Text = ComboBox1.SelectedValue.ToString
121
121
  ```
122
122
  解決?しました。
123
+ 変更後
124
+ textbox1が値段、textbox2を文字を入力(検索)にしました。
123
125
  ###わからない事、教えてほしいこと
124
126
  **文字を入力後、comboboxのアイテムが消える**
125
127
  「あ」を入れてもあり、ありんこのみ表示しない

3

文字の修正と書き直し

2019/02/21 15:03

投稿

退会済みユーザー
title CHANGED
@@ -1,1 +1,1 @@
1
- テキストボックスに文字を検索させたい
1
+ テキストボックスに文字を検索とselectindexを変更したい
body CHANGED
@@ -1,28 +1,85 @@
1
- ###前提・現したい
1
+ ###実践、やりたい変更したい場所
2
- 変更前のコード
2
+ **変更前のコード**
3
3
  ```ここに言語を入力
4
+ Imports System.Globalization
5
+
6
+ Public Class Form1
7
+ Private list As New List(Of String)()
8
+ Private Sub Kaou_Load(sender As Object, e As EventArgs) Handles MyBase.Load
9
+ list.Add("あり")
10
+ list.Add("ありんこ")
11
+ list.Add("いぬ")
12
+ list.Add("いのしし")
13
+ list.Add("うさぎ")
14
+ end sub
4
15
  Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
5
16
  If ComboBox1.SelectedIndex = 0 Then
6
- TextBox3.Text = "1"
17
+ TextBox2.Text = "10"
7
18
  End If
19
+ If ComboBox1.SelectedIndex = 1 Then
20
+ TextBox2.Text = "10"
21
+ End If
22
+ If ComboBox1.SelectedIndex = 2 Then
23
+ end if
24
+ If ComboBox1.SelectedIndex = 3 Then
25
+ TextBox2.Text = "100000"
26
+ End If
27
+ If ComboBox1.SelectedIndex = 4 Then
28
+ TextBox2.Text = "150000"
29
+ End If
30
+ end sub
31
+ '値段は例です全部で5個あります
32
+ Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
33
+ 'テキストを書き換えるたびに、
34
+ 'リストの内容を先頭一致でフィルタリング
35
+ Dim ci = New CultureInfo("ja-jp").CompareInfo
36
+ Dim opt As CompareOptions
37
+ opt = opt Or CompareOptions.IgnoreWidth '全角と半角を区別しない
38
+ opt = opt Or CompareOptions.IgnoreKanaType 'ひらがなとカタカナを区別しない
39
+ opt = opt Or CompareOptions.IgnoreCase '大文字と小文字を区別しない
40
+ opt = opt Or CompareOptions.IgnoreNonSpace '文字列比較で分音文字などの結合の分音文字を無視することを示します。
41
+ opt = opt Or CompareOptions.IgnoreSymbols '文字列の比較が空白文字が区切り記号、通貨記号、パーセント記号、数学記号、アンパサンド、やなどの記号を無視することを示します。
42
+
43
+ Dim txt As String = TextBox3.Text
44
+
45
+ ComboBox1.DataSource = list.Where(
46
+ Function(s)
47
+ Return 0 = ci.Compare(Strings.Left(s, txt.Length), txt, opt)
48
+ End Function).ToArray()
49
+ End Sub
50
+ End Class
51
+
8
52
  ```
53
+ **変更前のコードは全体のコードです。**
54
+ ・「変更前」で実践
9
- 50個分のアイテムをlist.Add("")間にれたのをindextextbox3
55
+ textbox2=値段、textbox3=文字力するその文字が表示される
56
+ あ=あり、ありんこ(カタカナでも可能)
57
+ い=いぬ、いのしし
10
- これを書き直しすることにで破棄しした
58
+ う=うさぎ・・・ど他文字は表示されせん
11
59
 
60
+ ---
61
+ ・indexとtextbox2これでやってます。
62
+ この場合新しいアイテム追加(間に入れるときも)して書き出し
63
+ 追加前
64
+ index="1"Then’ありんこ
65
+ textbox2.text=""
66
+ 追加後
67
+ index="2"Then'ありんこ
68
+ textbox2.text=""
69
+ こんな感じで何個があります。
70
+ これを書き直しなど大変なのでindexとtextbox破棄しました。
12
71
 
13
- ・コンボボックスアイテムをテキストボックスに入力するだけで
14
- 文字を検索できるようにしたい事。
72
+ 変更後のコード
15
- ・textbox2に「あ」がつく文字をいれると
16
- combobox1にあが付く文字だけ表示させたい事。
17
73
 
18
- コンボボックス
74
+ ```ここに言語を入力
19
- ```Imports System.Globalization
75
+ Imports System.Globalization
20
- Public Class Sentakusenzai
76
+ Public Class Form1
21
77
  Private list As New Dictionary(Of String, Integer)
22
78
 
23
- Private Sub Sentakusenzai_Load(sender As Object, e As EventArgs) Handles MyBase.Load
79
+ Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
80
+      ’変更前の list.Add("あり")
81
+
24
- 'アイテム
82
+ '変更後のアイテム
25
-     
26
83
  list.Add("あり", 1)
27
84
  list.Add("ありんこ", 2)
28
85
  list.Add("いぬ", 1)
@@ -32,12 +89,11 @@
32
89
  ComboBox1.ValueMember = "value"
33
90
  ComboBox1.DataSource = New BindingSource(list, Nothing)
34
91
  ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
35
-
92
+ End Sub
93
+ Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
94
+ TextBox1.Text = ComboBox1.SelectedValue.ToString
36
95
  End Sub
37
-
38
- ```
39
- **文字を検索**
40
- ``` Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
96
+ Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
41
97
  Dim cca = New CultureInfo("ja-jp").CompareInfo
42
98
  Dim opt As CompareOptions
43
99
  opt = opt Or CompareOptions.IgnoreWidth '全角と半角を区別しない
@@ -50,86 +106,31 @@
50
106
 
51
107
  ComboBox1.DataSource = New BindingSource(list.Where(
52
108
  Function(s)
53
- Return 0 = cca.Compare(Strings.Left(s.Value, txt.Length), txt, opt)
109
+ Return 0 = cca.Compare(Strings.Left(s.Key, txt.Length), txt, opt)
54
110
  End Function).ToArray(), Nothing)
55
111
  End Sub
56
112
 
113
+ End Class
57
114
  ```
115
+ 全体でのコードです。
116
+ ###変更後のやりたい事と修正したい
117
+ **変更後のコードで文字をいれても変わりません**
58
- **値段**
118
+ **値段の方は
59
119
  ```ここに言語を入力
60
- Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
61
- Dim de As New DictionaryEntry
62
- Dim cb1 As New Integer
63
- de = CType(ComboBox1.SelectedItem, DictionaryEntry)
64
- cb1 = de.Value
65
- TextBox1.Text = (cb1).ToString()
120
+ TextBox1.Text = ComboBox1.SelectedValue.ToString
66
- End Sub
67
121
  ```
122
+ 解決?しました。
68
- ###こと、やりたい事
123
+ ###わからない事、教えてほこと
69
- 回答させていただいた通行った結果は
70
- ###エラー
71
- ```ここに言語を入力
72
- de = CType(ComboBox1.SelectedItem, DictionaryEntry)
124
+ **文字を入力後、comboboxのアイテムが消える**
73
- 指定さたキャストは有効ではありませ。'
125
+ 「あ」を入てもあり、ありこのみ表示しない
126
+ **変更前はあをいれるとあり、ありんことほかの文字は出ません。**
127
+ このように実行させたいのですがご迷惑をおかけしすいません。
128
+ ・文字を入力後の改善修正を教えてもらえますでしょうか?
129
+ 申し訳ございません。変更前と変更後の書き直ししました。
130
+ いろいろと試しにコード変えてみましたが4,5時間やってもできませんでした。
74
131
 
75
- ```
76
- 値段を表示するんですがエラーが出てしまいました。
77
- 回避することは可能でしょうか?
78
- ・「文字を入力」したらCombobox1でなぜが「あ」が付いた文字が表示されず
79
- 他の文字も表示されてしまいました。
80
- 変更前のコード
81
- ```ここに言語を入力
82
- Private list As New List(Of String)()
83
- foam1
84
-
85
- Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
86
- 'テキストを書き換えるたびに、
87
- 'リストの内容を先頭一致でフィルタリング
88
- Dim ci = New CultureInfo("ja-jp").CompareInfo
89
- Dim opt As CompareOptions
90
- opt = opt Or CompareOptions.IgnoreWidth '全角と半角を区別しない
91
- opt = opt Or CompareOptions.IgnoreKanaType 'ひらがなとカタカナを区別しない
92
- opt = opt Or CompareOptions.IgnoreCase '大文字と小文字を区別しない
93
- opt = opt Or CompareOptions.IgnoreNonSpace '文字列比較で分音文字などの結合の分音文字を無視することを示します。
94
- opt = opt Or CompareOptions.IgnoreSymbols '文字列の比較が空白文字が区切り記号、通貨記号、パーセント記号、数学記号、アンパサンド、やなどの記号を無視することを示します。
95
-
96
- Dim txt As String = TextBox3.Text
97
-
98
- ComboBox1.DataSource = list.Where(
99
- Function(s)
100
- Return 0 = ci.Compare(Strings.Left(s, txt.Length), txt, opt)
101
- End Function).ToArray()
102
- End Sub
103
- ```
104
- この場合はちゃんとあだけの文字をいれたらcomboboxであが付く文字が表示される
105
- 変更後の場合は
106
- ```ここに言語を入力
107
- ComboBox1.DataSource = New BindingSource(list.Where(
108
- Function(s)
109
- Return 0 = cca.Compare(Strings.Left(s.Key, txt.Length), txt, opt)
110
- End Function).ToArray(), Nothing)
111
- End Sub
112
- ```
113
- 変更前
114
- ```ここに言語を入力
115
- Dim txt As String = TextBox3.Text
116
-
117
- ComboBox1.DataSource = list.Where(
118
- Function(s)
119
- Return 0 = ci.Compare(Strings.Left(s, txt.Length), txt, opt)
120
- End Function).ToArray()
121
- End Sub
122
- ```
123
- s,とs.でしょうか?
124
-
125
- 文字を入力後comboboxの表示があが付く文字に変わるようにしたい
126
- エラーを回避させたい
127
- 修正しました。
128
- よろしくお願いいたします。
132
+ 初心者ですがよろしくお願いいたします。
129
-
130
- 初心者ですので教えてください。
131
-
132
- ###バージョンなど
133
+ ###バージョン
133
- **Windows10**
134
+ Windows10
134
- **Vistual Basic(VB.net)**
135
+ Vistual basic
135
- **Vistual Studio 2019を使ってます。**
136
+ Vistual studio2019を使ってます。

2

説明文と内容を変更しました。

2019/02/21 15:01

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,25 +1,43 @@
1
- ###前提・実現したいこと**
1
+ ###前提・実現したいこと
2
+ ・変更前のコード
3
+ ```ここに言語を入力
4
+ Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
5
+ If ComboBox1.SelectedIndex = 0 Then
6
+ TextBox3.Text = "1"
7
+ End If
8
+ ```
9
+ 50個分のアイテムをlist.Add("")間に入れたのをindexとtextbox3
10
+ これを書き直しすることになるので破棄しました。
11
+
12
+
2
13
  ・コンボボックスアイテムをテキストボックスに入力するだけで
3
14
  文字を検索できるようにしたい事。
4
- テキストボックスにあという文字をいれるとコンボボックスのアイテムが
15
+ textbox2」がつく文字をいれると
5
- **「」の文字だけ表示させたい事です**
16
+ combobox1にが付く文字だけ表示させたい事。
6
17
 
18
+ コンボボックス
19
+ ```Imports System.Globalization
20
+ Public Class Sentakusenzai
21
+ Private list As New Dictionary(Of String, Integer)
22
+
23
+ Private Sub Sentakusenzai_Load(sender As Object, e As EventArgs) Handles MyBase.Load
24
+ 'アイテム
25
+     
26
+ list.Add("あり", 1)
27
+ list.Add("ありんこ", 2)
28
+ list.Add("いぬ", 1)
29
+ list.Add("いぬねこ", 2)
30
+
31
+ ComboBox1.DisplayMember = "key"
32
+ ComboBox1.ValueMember = "value"
33
+ ComboBox1.DataSource = New BindingSource(list, Nothing)
34
+ ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
35
+
36
+ End Sub
37
+
7
38
  ```
8
- Imports System.Globalization
9
- Form1
10
- Private list As New List(Of String)()
11
- foam_load
39
+ **文字を検索**
12
- list.add("あり")
13
- list.add("ありんこ")
14
- list.add("いぬ")
15
- list.add("いぬねこ")
16
- end sub
17
- Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
18
- If ComboBox1.SelectedIndex = 0 Then
19
- TextBox2.Text = "1"
20
- End If
21
- '省略
22
- Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
40
+ ``` Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
23
41
  Dim cca = New CultureInfo("ja-jp").CompareInfo
24
42
  Dim opt As CompareOptions
25
43
  opt = opt Or CompareOptions.IgnoreWidth '全角と半角を区別しない
@@ -28,64 +46,86 @@
28
46
  opt = opt Or CompareOptions.IgnoreNonSpace '文字列比較で分音文字などの結合の分音文字を無視することを示します。
29
47
  opt = opt Or CompareOptions.IgnoreSymbols '文字列の比較が空白文字が区切り記号、通貨記号、パーセント記号、数学記号、アンパサンド、やなどの記号を無視することを示します。
30
48
 
49
+ Dim txt As String = TextBox2.Text
50
+
51
+ ComboBox1.DataSource = New BindingSource(list.Where(
52
+ Function(s)
53
+ Return 0 = cca.Compare(Strings.Left(s.Value, txt.Length), txt, opt)
54
+ End Function).ToArray(), Nothing)
55
+ End Sub
56
+
57
+ ```
58
+ **値段**
59
+ ```ここに言語を入力
60
+ Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
61
+ Dim de As New DictionaryEntry
62
+ Dim cb1 As New Integer
63
+ de = CType(ComboBox1.SelectedItem, DictionaryEntry)
64
+ cb1 = de.Value
65
+ TextBox1.Text = (cb1).ToString()
66
+ End Sub
67
+ ```
68
+ ###試したこと、やりたい事
69
+ 回答させていただいた通行った結果は
70
+ ###エラー
71
+ ```ここに言語を入力
72
+ de = CType(ComboBox1.SelectedItem, DictionaryEntry)
73
+ 指定されたキャストは有効ではありません。'
74
+
75
+ ```
76
+ 値段を表示するんですがエラーが出てしまいました。
77
+ 回避することは可能でしょうか?
78
+ ・「文字を入力」したらCombobox1でなぜが「あ」が付いた文字が表示されず
79
+ 他の文字も表示されてしまいました。
80
+ 変更前のコード
81
+ ```ここに言語を入力
82
+ Private list As New List(Of String)()
83
+ foam1
84
+
85
+ Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
86
+ 'テキストを書き換えるたびに、
87
+ 'リストの内容を先頭一致でフィルタリング
88
+ Dim ci = New CultureInfo("ja-jp").CompareInfo
89
+ Dim opt As CompareOptions
90
+ opt = opt Or CompareOptions.IgnoreWidth '全角と半角を区別しない
91
+ opt = opt Or CompareOptions.IgnoreKanaType 'ひらがなとカタカナを区別しない
92
+ opt = opt Or CompareOptions.IgnoreCase '大文字と小文字を区別しない
93
+ opt = opt Or CompareOptions.IgnoreNonSpace '文字列比較で分音文字などの結合の分音文字を無視することを示します。
94
+ opt = opt Or CompareOptions.IgnoreSymbols '文字列の比較が空白文字が区切り記号、通貨記号、パーセント記号、数学記号、アンパサンド、やなどの記号を無視することを示します。
95
+
31
96
  Dim txt As String = TextBox3.Text
32
97
 
33
98
  ComboBox1.DataSource = list.Where(
34
99
  Function(s)
35
- Return 0 = cca.Compare(Strings.Left(s, txt.Length), txt, opt)
100
+ Return 0 = ci.Compare(Strings.Left(s, txt.Length), txt, opt)
36
101
  End Function).ToArray()
37
102
  End Sub
38
103
  ```
39
- ###試したこと
40
- 文字を入力すると出来ます。ただ、こではコンボボックスに新に追加した場合
104
+ この場合はちゃんとあだけの文字をれたらcomboboxであが付く文字が表示される
41
- コンボボックスselectindex="0"~これも書き直しすることになってしまいます。
42
- [DictionaryEntry](https://jehupc.exblog.jp/9812996/)
43
- ###改(ソースコードを変した)変更
105
+ 変更後の場合は
44
106
  ```ここに言語を入力
45
- Imports System.Globalization
46
- 'アイテム
47
- With ComboBox1
48
- .Items.Add(New DictionaryEntry("ありんこ", 1))
49
- .Items.Add(New DictionaryEntry("あり", 2))
107
+ ComboBox1.DataSource = New BindingSource(list.Where(
50
- .Items.Add(New DictionaryEntry("いぬ", 1))
51
- .Items.Add(New DictionaryEntry("いぬねこ", 2))
52
- .DisplayMember = "key"
53
- .ValueMember = "value"
54
- End With
108
+ Function(s)
55
-
56
- Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
57
- Dim den As New DictionaryEntry
58
- Dim cbd As New Integer
59
- den = CType(ComboBox1.SelectedItem, DictionaryEntry)
109
+ Return 0 = cca.Compare(Strings.Left(s.Key, txt.Length), txt, opt)
60
- cbd = de.Value
61
- TextBox1.Text = (cbd).ToString()
110
+ End Function).ToArray(), Nothing)
62
111
  End Sub
63
- Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
64
- 'テキストボックス3と同じ
65
112
  ```
66
- ###試したこと・やりたいこと
67
- 変更前のコードはそのアイテム追加後selectindex="*"then
68
- *はselectindexを破棄して変更後add("あり",1)に改変して
69
- textbox1に選択されたら「1」と表示されます。
70
- textbox2は文字を入力するとコンボボックスに
71
- あが付く文字だけを表示(変更前)させたいんですが
113
+ 変更前
72
114
  ```ここに言語を入力
115
+ Dim txt As String = TextBox3.Text
116
+
73
- ComboBox1.DataSource = New BindingSource(list, Nothing)
117
+ ComboBox1.DataSource = list.Where(
74
- list.Where(
75
118
  Function(s)
76
119
  Return 0 = ci.Compare(Strings.Left(s, txt.Length), txt, opt)
77
- End Function).ToString()
120
+ End Function).ToArray()
78
121
  End Sub
79
122
  ```
80
- 教えていただいた通コードを追加してみたところ
81
- 文字を入力するとコンボボックスアイテムが空白(消えました)
82
- 後foam‗roadに
123
+ s,とs.でしょうか?
83
- ```
84
- ComboBox1.DataSource = New BindingSource(list, Nothing)
85
124
 
86
- ```
87
- そしたらコンボボックスが何もっていない状態でした
125
+ 文字を力後comboboxの表示があが付く文字に変わるようにした
126
+ エラーを回避させたい
88
- すいせん
127
+ 修正しした
128
+ よろしくお願いいたします。
89
129
 
90
130
  初心者ですので教えてください。
91
131
 

1

文字の修正

2019/02/21 08:14

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -64,16 +64,30 @@
64
64
  'テキストボックス3と同じ
65
65
  ```
66
66
  ###試したこと・やりたいこと
67
- 変更前のコードはそのアイテム追加後selectindex="*"
67
+ 変更前のコードはそのアイテム追加後selectindex="*"then
68
+ *はselectindexを破棄して変更後add("あり",1)に改変して
69
+ textbox1に選択されたら「1」と表示されます。
68
- 追加して番号を書き換えする(数字を入れ直し)
70
+ textbox2字を入力するとコンボボックスに
71
+ あが付く文字だけを表示(変更前)させたいんですが
72
+ ```ここに言語を入力
73
+ ComboBox1.DataSource = New BindingSource(list, Nothing)
74
+ list.Where(
75
+ Function(s)
76
+ Return 0 = ci.Compare(Strings.Left(s, txt.Length), txt, opt)
77
+ End Function).ToString()
78
+ End Sub
79
+ ```
80
+ 教えていただいた通コードを追加してみたところ
69
- のがても大変になってしいまてこれを改善(変更
81
+ 文字を入力するコンボボックスアイテムが空白(消えまし
82
+ 後foam‗roadに
83
+ ```
84
+ ComboBox1.DataSource = New BindingSource(list, Nothing)
70
85
 
71
- 変更後のコードで文字を検索入れると
86
+ ```
72
- コンボボックス消えしました。
87
+ そしたらコンボボックスが何も入っていない状態でした。
73
- 検索入力した「あ」を入れるとあだけ表示させたいんです(変更前は出来ます。)
88
+ ません。
74
89
 
75
- 初心者ですのでコード分かりにくいかもしれませんが
76
- 教えてください。
90
+ 初心者ですので教えてください。
77
91
 
78
92
  ###バージョンなど
79
93
  **Windows10**