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 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
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
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
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
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
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
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
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
>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
>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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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.
...
|
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...
|
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"...
|
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...
|
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)....
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
| |