Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Access VB.NET
how to get the selected item from listbox(retrived items from database) to another form in vb.net?
Posted 4-May-13 22:15pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Exactly how you do it depends on the relationship between the two forms: Is one form the child of another? Or are they both children of a third form?
There are a set of tips here which describe the process:
 
Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]
 
The code is in C#, but it should be pretty easy to translate to VB.
  Permalink  
Comments
sandhyagor at 5-May-13 5:23am
   
thnak you..
but two forms are different than each other.. they dont have any relationship..
then what to do???
OriginalGriff at 5-May-13 5:46am
   
They do - because unless they are in different applications then they will be opened by something.
If Form1 opens Form2 to do something, then Form1 is the Parent of Form2 and Form2 is the Child.
If both Form1 and Form2 are opened by Form3, then Form3 is the parent, and the others are both children. The parent has to know that the children exist and what type of form they are, but the children should not know what the parent is.
 
Without looking at you code, I can't tell you which of your forms is which!
sandhyagor at 5-May-13 6:14am
   
actually there is one form namely test_selection from where through listbox user can select test(records in the listbox is retrived from database)and then one another form is dispalyed and then after main exam form ll be display. i want to display the selected item from listbox(of test_selection form) to the exam form.
OriginalGriff at 5-May-13 6:26am
   
So are the "one another form" and "main exam form" displayed from test_selection? As in at some point you will have code like:
MyOtherForm mof = new MyOtherForm();
mof.ShowDialog();
or
MyOtherForm mof = new MyOtherForm();
mof.Show();
And similar for your MainExamForm.
Where is that code? Which form is it in?
sandhyagor at 5-May-13 8:15am
   
yea its true..
another form is displayed after test_selection and mainExam form is diaplayed after anotherform. and my question is that how to get selected item of listbox(of test_selection form) to the mainexam form???
OriginalGriff at 5-May-13 8:21am
   
When you display test_selection, you use ShowDialog, yes?
So when it returns, use properties to get the data from the text_selection instance into your method or class. Then, when you create the mainexam form, set the values via it's properties.
 
This is a lot easier to do than explain without seeing your code! :laugh:
Download one of the samples from the tips I linked to, and you will see what I mean.
sandhyagor at 5-May-13 8:35am
   
cant understands from ur links :(
will you please write code for me here in which form i have to write which code...
how can i send here the whole code.. not possible
sandhyagor at 5-May-13 22:50pm
   
had write this code in class1 :
Public Class Class1
Dim select1 As String
Sub New()
selection = Test_Selection.ListBox1.SelectedItem
End Sub
Public Property selection() As String
Get
Return select1
End Get
Set(ByVal value As String)
select1 = value
End Set
End Property
End Class

And this code in exam form :
Private Sub exam_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim obj As New Class1()
Label6.Text = obj.selection
end sub
 
but its not working :(
OriginalGriff at 6-May-13 8:29am
   
Oh dear, oh dear, oh dear...
 
Look at the samples: you really need to go back to first principles here - you don't even seem to know what an instance is. This will be a real problem in understanding what you have to do.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 295
1 OriginalGriff 249
2 Sergey Alexandrovich Kryukov 205
3 Aajmot Sk 197
4 Sinisa Hajnal 176
0 OriginalGriff 7,800
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 5 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100