Trying to return a selected listbox item to another form .tried lots of
ways; defining public variables and passing those as well as textboxes ..I'
m able to display the chosen item on it's form in a textbox and I'm able to
pass other variables to the 2nd form, but not the data I want . I should add
this is a smartdeviceappl ication(if that matters; not sure)
Here's most of the test code .
(for form 1)
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
ListBox1.Items. Add("audi")
ListBox1.Items. Add("buick")
ListBox1.Items. Add("chevy")
ListBox1.Items. Add("ford")
End Sub
Public curitem As String
Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
' Dim curItem As String = ListBox1.Select edItem.ToString ()
'Friend curItem As String
curItem = ListBox1.Select edItem
TextBox1.Text = curItem
vcar = curItem
End Sub
Public Property vcar() As String ' nothing comes back from this
Get
Return ListBox1.Select edItem
'return vcar
'return curitem
End Get
Set(ByVal Value As String)
'TextBox1.Text = Value
End Set
End Property
Public Property vn() As String 'this retuns "textbox1"
Get
Return TextBox1.Text
End Get
Set(ByVal Value As String)
TextBox1.Text = Value
End Set
End Property
Public Property t() As String 'this works
Get
Return "test"
End Get
Set(ByVal Value As String)
End Set
End Property
Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button3.Click
Dim f2 As Form2
f2 = New Form2
f2.Show()
End Sub
On form2 I've got
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
TextBox1.Text = f1.vcar
TextBox2.Text = f1.vn
TextBox3.Text = f1.t
End Sub 2 4880
Ok, there is a lot going on here that isn't right but it seems to me this
biggest problem you are having is that Form2 never has access to Form1. You
need to pass a reference to Form2 so it can open Form1 public members. Here
is the working idea. The key points are that when I make a new Form2, I
pass in a copy of F1. Check out the changes in the new constructor for
Form2.
Good luck
Chris
Public Class Form1
Inherits System.Windows. Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ListBox1 As System.Windows. Forms.ListBox
Friend WithEvents Button1 As System.Windows. Forms.Button
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.ListBox1 = New System.Windows. Forms.ListBox
Me.Button1 = New System.Windows. Forms.Button
Me.SuspendLayou t()
'
'ListBox1
'
Me.ListBox1.Loc ation = New System.Drawing. Point(28, 62)
Me.ListBox1.Nam e = "ListBox1"
Me.ListBox1.Siz e = New System.Drawing. Size(120, 95)
Me.ListBox1.Tab Index = 5
'
'Button1
'
Me.Button1.Loca tion = New System.Drawing. Point(176, 72)
Me.Button1.Name = "Button1"
Me.Button1.TabI ndex = 6
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(292, 266)
Me.Controls.Add (Me.Button1)
Me.Controls.Add (Me.ListBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)
End Sub
#End Region
Public curitem As String
Public ReadOnly Property GetCurrentSelec tedItem() As String ' nothing
comes back from this
Get
Return ListBox1.Select edItem
End Get
End Property
Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
ListBox1.Items. Add("audi")
ListBox1.Items. Add("buick")
ListBox1.Items. Add("chevy")
ListBox1.Items. Add("ford")
ListBox1.Select edIndex = 0
End Sub
Private Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim f2 As Form2
f2 = New Form2(Me)
f2.Show()
End Sub
End Class
Public Class Form2
Inherits System.Windows. Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New(ByVal F As Form1)
MyBase.New()
F1 = F
'This call is required by the Windows Form Designer.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows. Forms.Button
Friend WithEvents TextBox1 As System.Windows. Forms.TextBox
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.Button1 = New System.Windows. Forms.Button
Me.TextBox1 = New System.Windows. Forms.TextBox
Me.SuspendLayou t()
'
'Button1
'
Me.Button1.Loca tion = New System.Drawing. Point(40, 72)
Me.Button1.Name = "Button1"
Me.Button1.TabI ndex = 3
Me.Button1.Text = "Button1"
'
'TextBox1
'
Me.TextBox1.Loc ation = New System.Drawing. Point(32, 40)
Me.TextBox1.Nam e = "TextBox1"
Me.TextBox1.Tab Index = 4
Me.TextBox1.Tex t = "TextBox1"
'
'Form2
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(176, 126)
Me.Controls.Add (Me.TextBox1)
Me.Controls.Add (Me.Button1)
Me.Name = "Form2"
Me.Text = "Form2"
Me.ResumeLayout (False)
End Sub
#End Region
Dim F1 As Form1
Private Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.Click
TextBox1.Text = F1.GetCurrentSe lectedItem()
End Sub
End Class
Got it working by adding "shared"
Public Shared curitem As String
and (perhaps) by moving the declaration to the tip of the file, as in :
Public Class Form1
Inherits System.Windows. Forms.Form
Friend WithEvents ListBox1 As System.Windows. Forms.ListBox
Friend WithEvents Button1 As System.Windows. Forms.Button
Friend WithEvents MainMenu1 As System.Windows. Forms.MainMenu
Public Shared curitem As String
"baret bonden" <ar****@network s-cc.com> wrote in message
news:30******** *****@uni-berlin.de... Trying to return a selected listbox item to another form .tried lots of ways; defining public variables and passing those as well as textboxes
...I' m able to display the chosen item on it's form in a textbox and I'm able
to pass other variables to the 2nd form, but not the data I want . I should
add this is a smartdeviceappl ication(if that matters; not sure) Here's most of the test code .
(for form 1) Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
ListBox1.Items. Add("audi")
ListBox1.Items. Add("buick")
ListBox1.Items. Add("chevy")
ListBox1.Items. Add("ford")
End Sub
Public curitem As String
Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button2.Click
' Dim curItem As String = ListBox1.Select edItem.ToString ()
'Friend curItem As String
curItem = ListBox1.Select edItem
TextBox1.Text = curItem
vcar = curItem
End Sub Public Property vcar() As String ' nothing comes back from this
Get
Return ListBox1.Select edItem
'return vcar
'return curitem
End Get Set(ByVal Value As String) 'TextBox1.Text = Value End Set
End Property Public Property vn() As String 'this retuns "textbox1"
Get
Return TextBox1.Text
End Get
Set(ByVal Value As String)
TextBox1.Text = Value
End Set
End Property Public Property t() As String 'this works
Get
Return "test"
End Get
Set(ByVal Value As String) End Set
End Property Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button3.Click
Dim f2 As Form2
f2 = New Form2
f2.Show()
End Sub
On form2 I've got Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
TextBox1.Text = f1.vcar
TextBox2.Text = f1.vn
TextBox3.Text = f1.t
End Sub
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Geir Baardsen |
last post by:
Hi!
I have the following headpuzzle:
On a form (frmAgenda) I have a calendar control and a listbox.
When user clicks date in calendar, the listbox will show some
information that will be displayed in several rows.
Then the user can doubleclick an item in the listbox and the chosen item
will be displayed in another form (frmDisplay). At the
|
by: John O'Donnell |
last post by:
Hello
on my asp.net code I load up a listbox on the page_load method. The problem
is that while the items I have added in the page_load do appear when i run
the page, i am unable to get the value of the selected item using
listbox.selectedvalue etc.
somehow the server side is unaware that i have selected an item.
In fact if i set the listbox.selecteditem=0; it always returns this item
|
by: Karen Grube |
last post by:
Hi!
I'm using a standard server side ASP.Net listbox control on a web form.
The page is basically various shades of green. The listbox itself has a pale
green background and forest green text and a forest green border. However,
when you move the cursor from one item to the next within the listbox or you
click on an item in the listbox to select it, the background turns to the
standard windows dark blue with white letters. Well, that...
|
by: Brian Henry |
last post by:
I have a list box bound to a data set, of course the datasource,datamember,
and valuemember are set, i tell it selecteditem = -1 to make nothing
selected, select mode is set to only one item at a time. When the list fills
the first item in the listbox has a background rectangle drawn but no focus
rectangle (this is NOT a custom drawn listbox, just a standard one).. now i
did set -1 as the selected item, but if i tab to the item the focus...
|
by: acord |
last post by:
Hi,
I am having problem to get a value of the selected item from a dropdown
listbox.
Here is the JS function;
function getSelectedItem(objSelect) {
alert("in getSelectedItem");
alert (objSelect.length);
alert (objSelect.value);
| |
by: John |
last post by:
I have a listbox that is databound when my form loads. A user
can then select and option using a drop down box. When the user
selects an option the corresponding items in the listbox gets selected.
How can I show those selected items at the top of my listbox. The
issue is when the user selects an item and it is in the middle of the list,
the user is not able to know an item it is selected or not unless they scroll
through the listbox.
|
by: Mitch |
last post by:
Is the following a correct representation of the relationship of the selected
index to selected item:
INDEX ITEM
0 "item 1"
1 "item 2"
2 "item 3"
and so on.
I keep getting the same string for selected index 0 and 1; i.e. both are
"item 1".
I'm new to C# and not exactly an accomplished programmer. Any suggestions?
|
by: rn5a |
last post by:
I am binding a DropDownList with records existing in a database table.
I want to add an extra item *SELECT COMPANY* at index 0 so that by
default, it gets selected. This is how I tried it but the extra item
just doesn't get added to the DropDownList:
=============================================
<script runat="server">
Sub Page_Load(..........)
Dim dSet As DataSet
Dim sqlConn As SqlConnection
|
by: Sunray |
last post by:
I have a form called the sales form and i have 2 sets of listboxes
So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which are not bound, I select from the bottom set and add to the top set which works fine, but now i decide to remove an item from the top set.
when i tried to use a remove item code it worked fine, it did delete the item form the list but it added...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |