473,386 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 4352
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
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
Oralloy
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,...
0
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...

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.