473,503 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

textbox and listbox

Hello,
I'm going around in circles with this problem and I hope someone can help me.

I have a listbox that is populated from a SQL Server database, with about 600 items, all strings.
I have a textbox on the same form, where I want to display which item is selected.

In the 'OnSelectedIndexChanged' event, I need code that has the textbox update to whatever value is currently selected in the listbox.

If I use the code:

TextBox1.Text = ListBox1.SelectedItem.toString

it diplays the incorrect item in the textbox.

If I use a datarow view with the following code:
Dim drv As DataRowView = lBoxCP.SelectedItem
txtCPMain.Text = drv("STR_CUTTING_PERMIT")
It works quite well, but after clicking several different items, the text box starts showing incorrect items.

SelectionMode is set to One.

Any suggestions?
Thanks,
Amber
Nov 20 '05 #1
12 4360
Hi,

Try binding the textbox and the listbox to the same datasource. The
currency manager will keep them in sync.

Ken
--------------
"amber" <an*******@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.com...
Hello,
I'm going around in circles with this problem and I hope someone can help me.
I have a listbox that is populated from a SQL Server database, with about 600 items, all strings. I have a textbox on the same form, where I want to display which item is selected.
In the 'OnSelectedIndexChanged' event, I need code that has the textbox update to whatever value is currently selected in the listbox.
If I use the code:

TextBox1.Text = ListBox1.SelectedItem.toString

it diplays the incorrect item in the textbox.

If I use a datarow view with the following code:
Dim drv As DataRowView = lBoxCP.SelectedItem
txtCPMain.Text = drv("STR_CUTTING_PERMIT")
It works quite well, but after clicking several different items, the text box starts showing incorrect items.
SelectionMode is set to One.

Any suggestions?
Thanks,
Amber

Nov 20 '05 #2
Hi,

Try binding the textbox and the listbox to the same datasource. The
currency manager will keep them in sync.

Ken
--------------
"amber" <an*******@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.com...
Hello,
I'm going around in circles with this problem and I hope someone can help me.
I have a listbox that is populated from a SQL Server database, with about 600 items, all strings. I have a textbox on the same form, where I want to display which item is selected.
In the 'OnSelectedIndexChanged' event, I need code that has the textbox update to whatever value is currently selected in the listbox.
If I use the code:

TextBox1.Text = ListBox1.SelectedItem.toString

it diplays the incorrect item in the textbox.

If I use a datarow view with the following code:
Dim drv As DataRowView = lBoxCP.SelectedItem
txtCPMain.Text = drv("STR_CUTTING_PERMIT")
It works quite well, but after clicking several different items, the text box starts showing incorrect items.
SelectionMode is set to One.

Any suggestions?
Thanks,
Amber

Nov 20 '05 #3
Hi Amber,

Are you sure you use the protected event 'OnSelectedIndexChanged' because
than I think you have to show some code to give us an idea what you are
doing.

Cor
Nov 20 '05 #4
Hi Amber,

Are you sure you use the protected event 'OnSelectedIndexChanged' because
than I think you have to show some code to give us an idea what you are
doing.

Cor
Nov 20 '05 #5
Thanks Ken

It is bound to the same dataset, isn't it? Here's my code

The list box is 1st populated by this code

Private Sub get_all_CPs(

lBoxCP.DataSource = Nothin
lBoxCP.Items.Clear(
lBoxCP.Refresh(

DsCP1.Clear(
SqlDA_CP.Fill(DsCP1

Dim dvCP As DataVie
dvCP = New DataVie

With dvC
.Table = DsCP1.Tables("TDT_CUTTING_PERMIT"
.Sort = "STR_CUTTING_PERMIT
End Wit

lBoxCP.DataSource = dvC
lBoxCP.DisplayMember = "STR_CUTTING_PERMIT
lBoxCP.Refresh(

End Su

And here's the listbox event code

Private Sub lBoxCP_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handle
lBoxCP.SelectedIndexChange

Dim drv As DataRowView = lBoxCP.SelectedIte
txtCPMain.Text = drv("STR_CUTTING_PERMIT"

End Su

Thanks
Ambe

Nov 20 '05 #6
Thanks Ken

It is bound to the same dataset, isn't it? Here's my code

The list box is 1st populated by this code

Private Sub get_all_CPs(

lBoxCP.DataSource = Nothin
lBoxCP.Items.Clear(
lBoxCP.Refresh(

DsCP1.Clear(
SqlDA_CP.Fill(DsCP1

Dim dvCP As DataVie
dvCP = New DataVie

With dvC
.Table = DsCP1.Tables("TDT_CUTTING_PERMIT"
.Sort = "STR_CUTTING_PERMIT
End Wit

lBoxCP.DataSource = dvC
lBoxCP.DisplayMember = "STR_CUTTING_PERMIT
lBoxCP.Refresh(

End Su

And here's the listbox event code

Private Sub lBoxCP_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handle
lBoxCP.SelectedIndexChange

Dim drv As DataRowView = lBoxCP.SelectedIte
txtCPMain.Text = drv("STR_CUTTING_PERMIT"

End Su

Thanks
Ambe

Nov 20 '05 #7
Hi Amber,

That is what I thought it is the

SelectedIndexChanged not OnSelectedIndexChanged, which exist also

However when you add that one row I did you can delete that complete event
in my opinion
\\\
lBoxCP.DataSource = dvCP
lBoxCP.DisplayMember = "STR_CUTTING_PERMIT"
txtCPMain.Text.DataBindings.Add(Text",dvCP,"SRT_CU TTING_PERMIT")
lBoxCP.Refresh()
///

I do not know if you fill the dataset more and than you can set by the clear
of the dataset
txtCPMain.Text.Databindings.clear

I hope this helps?

Cor
Nov 20 '05 #8
Hi Amber,

That is what I thought it is the

SelectedIndexChanged not OnSelectedIndexChanged, which exist also

However when you add that one row I did you can delete that complete event
in my opinion
\\\
lBoxCP.DataSource = dvCP
lBoxCP.DisplayMember = "STR_CUTTING_PERMIT"
txtCPMain.Text.DataBindings.Add(Text",dvCP,"SRT_CU TTING_PERMIT")
lBoxCP.Refresh()
///

I do not know if you fill the dataset more and than you can set by the clear
of the dataset
txtCPMain.Text.Databindings.clear

I hope this helps?

Cor
Nov 20 '05 #9
>I do not know if you fill the dataset more and than you can set by the
clear

typos

I do not know if you fill the dataset more than once and than you can set by
the clear
Nov 20 '05 #10
>I do not know if you fill the dataset more and than you can set by the
clear

typos

I do not know if you fill the dataset more than once and than you can set by
the clear
Nov 20 '05 #11
Hi,

Instead of setting the value in the selected index changed event
try this.

Private Sub get_all_CPs()

lBoxCP.DataSource = Nothing
lBoxCP.Items.Clear()
lBoxCP.Refresh()

DsCP1.Clear()
SqlDA_CP.Fill(DsCP1)

Dim dvCP As DataView
dvCP = New DataView

With dvCP
.Table = DsCP1.Tables("TDT_CUTTING_PERMIT")
.Sort = "STR_CUTTING_PERMIT"
End With

lBoxCP.DataSource = dvCP
lBoxCP.DisplayMember = "STR_CUTTING_PERMIT"
lBoxCP.Refresh()

txtCPMain.DataBindings.Add("Text", dvCP, "STR_CUTTING_PERMIT")
End Sub

Ken
--------------
"amber" <an*******@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
Thanks Ken,

It is bound to the same dataset, isn't it? Here's my code:

The list box is 1st populated by this code:

Private Sub get_all_CPs()

lBoxCP.DataSource = Nothing
lBoxCP.Items.Clear()
lBoxCP.Refresh()

DsCP1.Clear()
SqlDA_CP.Fill(DsCP1)

Dim dvCP As DataView
dvCP = New DataView

With dvCP
.Table = DsCP1.Tables("TDT_CUTTING_PERMIT")
.Sort = "STR_CUTTING_PERMIT"
End With

lBoxCP.DataSource = dvCP
lBoxCP.DisplayMember = "STR_CUTTING_PERMIT"
lBoxCP.Refresh()

End Sub

And here's the listbox event code:

Private Sub lBoxCP_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lBoxCP.SelectedIndexChanged

Dim drv As DataRowView = lBoxCP.SelectedItem
txtCPMain.Text = drv("STR_CUTTING_PERMIT")

End Sub

Thanks,
Amber

Nov 20 '05 #12
Hi,

Instead of setting the value in the selected index changed event
try this.

Private Sub get_all_CPs()

lBoxCP.DataSource = Nothing
lBoxCP.Items.Clear()
lBoxCP.Refresh()

DsCP1.Clear()
SqlDA_CP.Fill(DsCP1)

Dim dvCP As DataView
dvCP = New DataView

With dvCP
.Table = DsCP1.Tables("TDT_CUTTING_PERMIT")
.Sort = "STR_CUTTING_PERMIT"
End With

lBoxCP.DataSource = dvCP
lBoxCP.DisplayMember = "STR_CUTTING_PERMIT"
lBoxCP.Refresh()

txtCPMain.DataBindings.Add("Text", dvCP, "STR_CUTTING_PERMIT")
End Sub

Ken
--------------
"amber" <an*******@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
Thanks Ken,

It is bound to the same dataset, isn't it? Here's my code:

The list box is 1st populated by this code:

Private Sub get_all_CPs()

lBoxCP.DataSource = Nothing
lBoxCP.Items.Clear()
lBoxCP.Refresh()

DsCP1.Clear()
SqlDA_CP.Fill(DsCP1)

Dim dvCP As DataView
dvCP = New DataView

With dvCP
.Table = DsCP1.Tables("TDT_CUTTING_PERMIT")
.Sort = "STR_CUTTING_PERMIT"
End With

lBoxCP.DataSource = dvCP
lBoxCP.DisplayMember = "STR_CUTTING_PERMIT"
lBoxCP.Refresh()

End Sub

And here's the listbox event code:

Private Sub lBoxCP_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lBoxCP.SelectedIndexChanged

Dim drv As DataRowView = lBoxCP.SelectedItem
txtCPMain.Text = drv("STR_CUTTING_PERMIT")

End Sub

Thanks,
Amber

Nov 20 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1799
by: John R. | last post by:
I want to add a textbox next to each item in a Listbox on a Windows Form. The items need to be scrollable so I thought that maybe this is possible with an Owner Draw listbox. Searching the web...
28
4292
by: kfrost | last post by:
I know this is probably simple but I have a C# form and the class for the form is called sbaSynch. I have a textbox name txtServerName. I'm creating a class to manipulate XML functions so I...
4
1445
by: Kav | last post by:
As the title states, on my development PC there is a textbox which allways displays as a textbox. However on the clients PC it is showing previous entries he has made to the TextBox as a ListBox. ...
0
1209
by: Alpha | last post by:
Hi, I have a listbox and a textbox which is bind to the same dataset's column. So the selected item is display in the textbox availbe for editing. When I change the text in the textbox it has...
2
2222
by: fabrice | last post by:
Hi, I have a trouble with my TextBox Control and it's ViewState in my form... The property for it, is FALSE as following : <form id="frmSearchBre4" runat="Server"> <asp:textbox id="myID"...
3
1486
by: koonda | last post by:
Hi Guys, I have 5 listbox controls which I populated from the database tables. I tried it using the wizard. For all 5 listboxes and a single Repeater I used a SQL DataSourse Object and mapped this...
9
3199
by: zdrakec | last post by:
Hello all: Clearly, I'm not getting it! Here is the scenario: On a web page, I have two list boxen and a text box. The first listbox is populated at page load time (if it is not a postback)....
7
2839
by: billa856 | last post by:
Hi, My project is in MS Access 2002. In that I have two forms which I am using for Shipping Entry. Now First Form(ShippingAlerts) Is fillup by persons working in customer services.and the Second...
2
2727
by: E11esar | last post by:
Hi there. I am looking to use a dataset return from a webservice that is currently populating a listbox, to also populate a value in a textbox that is loaded once an item is selected from the...
9
10654
by: weirdguy | last post by:
Hello, Just for anyone information, there is a similar title "Search in Listbox" but it is via Combo Box. In case, anyone need it, I put a link to here. Please let me know if I break any rules...
0
7093
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...
0
7353
jinu1996
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...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
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...
0
5596
agi2029
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,...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
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 ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.