473,396 Members | 2,010 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,396 software developers and data experts.

array bound listbox

Hey all,

I was wondering, can I databind my text box to an array, if so what would my
datasource and member look like?

thanks in advance,
rodchar
Nov 21 '05 #1
3 1785
Rodchar,

I made a sample for you with wich I try to show this question and your
previous.
An normal array has no property therfore you can not bind to, so I show it
you with a table how to do it.

Therefore try it and tell me if this fits a little bit the problem.
\\\needs a form with 2 listboxes and one textbox
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim countries() As String = {"US", "EU"}
ListBox1.Items.AddRange(countries)
Dim table As New DataTable("Sample")
CreateTable(table)
Dim dv As New DataView(table)
ListBox2.DataSource = dv
dv.Sort = "Name"
ListBox2.DisplayMember = "Name"
TextBox1.DataBindings.Add(New Binding("Text", dv, "Id"))
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles
ListBox1.SelectedIndexChanged
DirectCast(ListBox2.DataSource, DataView).RowFilter = _
"Country = '" & ListBox1.SelectedItem.ToString & "'"
End Sub
Private Sub CreateTable(ByVal Table As DataTable)
Table.Columns.Add("Id")
Table.Columns.Add("Name")
Table.Columns.Add("Country")
For i As Integer = 0 To 7
Dim dr As DataRow = Table.NewRow
dr(0) = i.ToString
Table.Rows.Add(dr)
Next
Table.Rows(0)(1) = "Herfried K. Wagner"
Table.Rows(1)(1) = "Armin Zingler"
Table.Rows(2)(1) = "Ken Tucker"
Table.Rows(3)(1) = "CJ Taylor"
Table.Rows(4)(1) = "Jay B Harlow"
Table.Rows(5)(1) = "Terry Burns"
Table.Rows(6)(1) = "Tom Shelton"
Table.Rows(7)(1) = "Cor Ligthert"
Table.Rows(0)(2) = "EU"
Table.Rows(1)(2) = "EU"
Table.Rows(2)(2) = "US"
Table.Rows(3)(2) = "US"
Table.Rows(4)(2) = "US"
Table.Rows(5)(2) = "EU"
Table.Rows(6)(2) = "US"
Table.Rows(7)(2) = "EU"
End Sub
///

I hope this helps a little bit?

Cor

"rodchar" <ro*****@discussions.microsoft.com>
Hey all,

I was wondering, can I databind my text box to an array, if so what would
my
datasource and member look like?

thanks in advance,
rodchar

Nov 21 '05 #2
Rodchar,

I made a sample for you with wich I try to show this question and your
previous.
An normal array has no property therfore you can not bind to, so I show it
you with a table how to do it.

Therefore try it and tell me if this fits a little bit the problem.
\\\needs a form with 2 listboxes and one textbox
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim countries() As String = {"US", "EU"}
ListBox1.Items.AddRange(countries)
Dim table As New DataTable("Sample")
CreateTable(table)
Dim dv As New DataView(table)
ListBox2.DataSource = dv
dv.Sort = "Name"
ListBox2.DisplayMember = "Name"
TextBox1.DataBindings.Add(New Binding("Text", dv, "Id"))
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles
ListBox1.SelectedIndexChanged
DirectCast(ListBox2.DataSource, DataView).RowFilter = _
"Country = '" & ListBox1.SelectedItem.ToString & "'"
End Sub
Private Sub CreateTable(ByVal Table As DataTable)
Table.Columns.Add("Id")
Table.Columns.Add("Name")
Table.Columns.Add("Country")
For i As Integer = 0 To 7
Dim dr As DataRow = Table.NewRow
dr(0) = i.ToString
Table.Rows.Add(dr)
Next
Table.Rows(0)(1) = "Herfried K. Wagner"
Table.Rows(1)(1) = "Armin Zingler"
Table.Rows(2)(1) = "Ken Tucker"
Table.Rows(3)(1) = "CJ Taylor"
Table.Rows(4)(1) = "Jay B Harlow"
Table.Rows(5)(1) = "Terry Burns"
Table.Rows(6)(1) = "Tom Shelton"
Table.Rows(7)(1) = "Cor Ligthert"
Table.Rows(0)(2) = "EU"
Table.Rows(1)(2) = "EU"
Table.Rows(2)(2) = "US"
Table.Rows(3)(2) = "US"
Table.Rows(4)(2) = "US"
Table.Rows(5)(2) = "EU"
Table.Rows(6)(2) = "US"
Table.Rows(7)(2) = "EU"
End Sub
///

I hope this helps a little bit?

Cor

"rodchar" <ro*****@discussions.microsoft.com>
Hey all,

I was wondering, can I databind my text box to an array, if so what would
my
datasource and member look like?

thanks in advance,
rodchar

Nov 21 '05 #3
thanks for the snippet, that worked great.

"Cor Ligthert" wrote:
Rodchar,

I made a sample for you with wich I try to show this question and your
previous.
An normal array has no property therfore you can not bind to, so I show it
you with a table how to do it.

Therefore try it and tell me if this fits a little bit the problem.
\\\needs a form with 2 listboxes and one textbox
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim countries() As String = {"US", "EU"}
ListBox1.Items.AddRange(countries)
Dim table As New DataTable("Sample")
CreateTable(table)
Dim dv As New DataView(table)
ListBox2.DataSource = dv
dv.Sort = "Name"
ListBox2.DisplayMember = "Name"
TextBox1.DataBindings.Add(New Binding("Text", dv, "Id"))
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles
ListBox1.SelectedIndexChanged
DirectCast(ListBox2.DataSource, DataView).RowFilter = _
"Country = '" & ListBox1.SelectedItem.ToString & "'"
End Sub
Private Sub CreateTable(ByVal Table As DataTable)
Table.Columns.Add("Id")
Table.Columns.Add("Name")
Table.Columns.Add("Country")
For i As Integer = 0 To 7
Dim dr As DataRow = Table.NewRow
dr(0) = i.ToString
Table.Rows.Add(dr)
Next
Table.Rows(0)(1) = "Herfried K. Wagner"
Table.Rows(1)(1) = "Armin Zingler"
Table.Rows(2)(1) = "Ken Tucker"
Table.Rows(3)(1) = "CJ Taylor"
Table.Rows(4)(1) = "Jay B Harlow"
Table.Rows(5)(1) = "Terry Burns"
Table.Rows(6)(1) = "Tom Shelton"
Table.Rows(7)(1) = "Cor Ligthert"
Table.Rows(0)(2) = "EU"
Table.Rows(1)(2) = "EU"
Table.Rows(2)(2) = "US"
Table.Rows(3)(2) = "US"
Table.Rows(4)(2) = "US"
Table.Rows(5)(2) = "EU"
Table.Rows(6)(2) = "US"
Table.Rows(7)(2) = "EU"
End Sub
///

I hope this helps a little bit?

Cor

"rodchar" <ro*****@discussions.microsoft.com>
Hey all,

I was wondering, can I databind my text box to an array, if so what would
my
datasource and member look like?

thanks in advance,
rodchar


Nov 21 '05 #4

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

Similar topics

19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
1
by: Jakob Nielsen | last post by:
I have implemented a container class with IList and bound it to a listbox. Works just fine, but if i then add a new item to my list, the listbox is not updated. Looking at the definition for...
2
by: Daryll SHatz | last post by:
What object is returned by a bound (to a DataSet) ListBox when it is iterated? Listbox.DataSource = DataSet1.MyTable ListBox.DisplayMember = "Col1" ListBox.ValueMember = "Col2" Dim s as...
3
by: David L Wright II | last post by:
I have a data bound listbox that I want to select multiple lines then process each line. I bound a two column datatable to the listbox and set the DisplayMember property to the appropriate column...
0
by: Dave | last post by:
Hi all, I have a listbox that is complex bound by an arraylist. The problem is that when I delete an object from the arraylist, the listbox does not reflect those changes. I tried refreshing...
1
by: Spock | last post by:
Hi. I have a form with a listbox and a few label fields all bound to a dataset. When i navigate the listbox the labels change accordingly. so far everything works good. I made a button to...
3
by: Richard Albrecht | last post by:
I have been trying to figure out for days on how to read values from a Bound ListBox. The listBox gets the values from an Access Table. I can read values fine for Non-Bound ListBoxes, But the...
0
by: Tony Botelho | last post by:
I am fairly new to VB.NET and I am having some difficulty working with a bound listbox. On a simple form, I open a connection to my database and load a dataser. I then bind a listbox to the the...
8
by: Mike | last post by:
I'm passing an array to a listbox such as (1,2,3,4,5,6,7), I want to highlight (select) all the items in the listbox were the value equals (1,2,3,4,5,6,7). I'm able to only get the last value...
17
by: SenileOwl | last post by:
I'm very new to the whole programming thing and I'm having a little trouble with the syntax of my code. My code contains a bound listbox where the display member and value member are two different...
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:
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
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,...
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
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
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,...

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.