Jump to content
Sign in to follow this  
dxcypt

Visual Basic Related Combobox

Recommended Posts

Perlukan bantuan tentang code dan cara menghubungkan 2 ComboBox berkaitan dalam Visual Basic.
contoh apabila item di ComboBox1 di klik, ComboBox2 akan memaparkan item yang berbeza.
Ada sesiapa dpt tlg? Edited by dxcypt

Share this post


Link to post
Share on other sites
Contoh apabila item1 dalam ComboBox1 dipilih, ComboBox2 memaparkan senarai 1, 2, 3..
Dan apabila item2 dalam ComboBox1 dipilih, ComboBox2 memaparkan senarai 4, 5, 6..


Maksud saya, nilai dalam ComboBox2 bagi setiap item dalam ComboBox1 adalah berbeza..
So bagaimana nak hubungkaitkan kedua-dua ComboBox ni.. sad.gif

Share this post


Link to post
Share on other sites
maknanye mcm....
if combo1.selected = item1 then combo2.items = 1,2,3
if combo1.selected = item2 then combo2.items = 4,5,6 ??

camtu ke yg ko tanye?
value dlm combo2 tu kita dpt dari mana?
ke ko maksudkan bila kita pilih no 3 la katakan kat combo1,kita xnak ade no 3 kat combo2? Edited by sworn

Share this post


Link to post
Share on other sites
value dalam combo2 tu nk tulis sendiri dalam String

ya, kalau pilih no 3 dari combo1, value kt combo2 keluar lain dari value no1 dan no2 dari combo1

harap dapat bantu saya
thx for reply

Share this post


Link to post
Share on other sites
aku kurang fhm yg mana satu ko nak sbenarnye.so,aku bantai je la buat ye,harap2 menjawab soalan.
items kat combo1 aku xtau ko dpt dari mana,so,aku letak je value 1 sampai 6
pastu aku buat utk 2 situasi...

A== kalo kita pilih num 3 dari combo1,value selain daripada 3 akan kuar kat combo2(1,2,4,5,6)....

Dim i As Integer
i = 0
Do While (i < ComboBox1.Items.Count())
If (ComboBox1.SelectedIndex <> i) Then
ComboBox2.Items.Add(ComboBox1.Items.Item(i))
End If
i = i + 1
Loop

B== kalo kita pilih num 3 dari combo1,value selepas dari num 3 akan kuar kat combo2(3,4,5,6)
Dim i As Integer
i = ComboBox1.SelectedIndex
Do While (i < ComboBox1.Items.Count())
ComboBox2.Items.Add(ComboBox1.Items.Item(i))
i = i + 1
Loop

betul ke ko nak camni? Edited by sworn

Share this post


Link to post
Share on other sites
saya dah dapat, saya gunakan
Dim ch1 As String
ch1 = "Welcome"
ComboBox2.Items.Clear()
ComboBox2.Items.Add(ch1) 'saya cuma nk paparkan value selain dari ComboBox1

thx a lot sworn for help me! biggrin.gif Edited by dxcypt

Share this post


Link to post
Share on other sites
soalan sket..aku ni mmg suka berty layan je la..heheh...
kalo ko uat

Dim ch1 As String
ch1 = "Welcome"
ComboBox2.Items.Clear()
ComboBox2.Items.Add(ch1)


nilai comboBox2 akan ade Welcome je la..bukkanye apa yg ada kat comboBox1 yang x diselect

Share this post


Link to post
Share on other sites
aku rasa tak.sbab kalo ikut lojiknye...kalo kita tgk kat sini..
"If (ComboBox1.SelectedIndex <> i) Then"......
kita check kalo index utk item kat combo1 tu xsama dgn index sekarang,
baru kita tambah item tu kat combo2...
"ComboBox2.Items.Add(ComboBox1.Items.Item(i))"

aku try run lg skali td,elok je.aku rasa ko tak select lg item kat combo1 tu kot.sbab kita kan check "combo1.selectedindex".

yap....aku try run trus tanpa select item,mmg kuar value same je dua2.
ko ltk coding tu kat combobox1_selectedIndexChanged la lg senang.supaya dia trigger kalo kita select item je. Edited by sworn

Share this post


Link to post
Share on other sites
aku letak kat load tadi.. yup mmg jadi.. tankz...
tp y kene ade
i=i+1.. aku rasa ni bleh jadi kan list tu bertambah lagi je?

so aku use ComboBox2.Items.Clear() kAt atas ...so baru lah ianya menjadi..dah macam aku plak yg mintak toolonlg ni..hheheh.
rolleyes.gif Edited by aem1354

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...