473,554 Members | 3,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Binding an Array to a Combo Box

Perhaps I have the wrong construct, or misunderstand arrays in vb (2003)....
I've loaded a two-dimensional array (168 by 28) into memory as AcctArray.
{Dim AcctArray (500,28) as string...}

The AcctArray is loaded from a Quickbooks table, so there's no intrinsic
dataset to assign as datasource....

I want to have a combo table (or list table or whatever), currently named
cbAccounts, that can scroll through and maybe select items in the array. I
don't want to display all elements, just columns 1,2,6, and 13...

How do I construct this? A combo box is supposed to have as its datasource
an "array", but I can't seem to accomplish it. I can do

cbAccounts.Item s.Add(AcctArray (j,1) & " " & AcctArray(j,2) & " " &
Acctarray(j,6) & " " & AcctArray(j,13) )

but that doesn't accomplish my objectives...
Can someone give me a nudge?

Thanx in advance

--
Jim Shaffer
Nov 21 '05 #1
4 23415
You're on the right track. The datasource must implement IList.

As you concatenate the items you want to display from the array, use a loop
to add each resulting string to an ArrayList.

Then set the Combobox datasource to the arraylist.

When you select an item from the dropdown, the selectedindex property will
correspond to the second dimension index of your original array, assuming you
use each item in the original array.

You might also look into the displaymember and valuemember properties of the
ComboBox. If you wanted to use them you might use a Datatable instead of an
ArrayList. You would then assign those two properties to the appropriate
fields. This approach allows you to use the SelectedValue property of the
ComboBox.

www.charlesfarriersoftware.com

"Jim Shaffer" wrote:
Perhaps I have the wrong construct, or misunderstand arrays in vb (2003)....
I've loaded a two-dimensional array (168 by 28) into memory as AcctArray.
{Dim AcctArray (500,28) as string...}

The AcctArray is loaded from a Quickbooks table, so there's no intrinsic
dataset to assign as datasource....

I want to have a combo table (or list table or whatever), currently named
cbAccounts, that can scroll through and maybe select items in the array. I
don't want to display all elements, just columns 1,2,6, and 13...

How do I construct this? A combo box is supposed to have as its datasource
an "array", but I can't seem to accomplish it. I can do

cbAccounts.Item s.Add(AcctArray (j,1) & " " & AcctArray(j,2) & " " &
Acctarray(j,6) & " " & AcctArray(j,13) )

but that doesn't accomplish my objectives...
Can someone give me a nudge?

Thanx in advance

--
Jim Shaffer

Nov 21 '05 #2
Jim,

That usefull however terrible combobox have 2 methods for binding and one
method to add items.

It is the adding of items
the binding from the textboxpart (what is not your option)
the binding using the datasource to an Ilist array

You go now for adding items from the array to the arraylist from the
combobox.

That is not directly binding. What you can do is creating an array with
objects. Those you can bind using the datasource to the combobox. You can
get the information by casting it to a datarowview.

Because this I find more work than needed, I make in this kind of situations
just a datatable and bind it using the defaultview to that combobox. That
cost at least 10 times less time to do.

Just my thought,

Cor
Nov 21 '05 #3
Jim,
In addition to the other comments.

| How do I construct this? A combo box is supposed to have as its datasource
| an "array", but I can't seem to accomplish it. I can do
I've bound to single dimension arrays without any problems, I have not tried
binding to either 2 dimensional arrays or jagged/ragged arrays before.

I will see if I can find any information on binding to a 2 dimensional
array.

In the meantime, you could always convert the array into a DataTable.
Something like:

Const rows As Integer = 0
Const columns As Integer = 1

Dim table As DataTable

For rowIndex As Integer = acctArray.GetLo werBound(rows) To
acctArray.GetUp perBound(rows)
Dim row As DataRow = table.NewRow
For columnIndex As Integer = acctArray.GetLo werBound(column s) To
acctArray.GetUp perBound(column s)
row(columnIndex ) = acctArray(rowin dex, columnindex)
Next
table.Rows.Add( row)
Next

Which assumes that "table" has the same number of columns as your array.

Hope this helps
Jay

"Jim Shaffer" <us****@shaffer assoc.com> wrote in message
news:jO******** ************@co mcast.com...
| Perhaps I have the wrong construct, or misunderstand arrays in vb
(2003)....
| I've loaded a two-dimensional array (168 by 28) into memory as AcctArray.
| {Dim AcctArray (500,28) as string...}
|
| The AcctArray is loaded from a Quickbooks table, so there's no intrinsic
| dataset to assign as datasource....
|
| I want to have a combo table (or list table or whatever), currently named
| cbAccounts, that can scroll through and maybe select items in the array. I
| don't want to display all elements, just columns 1,2,6, and 13...
|
| How do I construct this? A combo box is supposed to have as its datasource
| an "array", but I can't seem to accomplish it. I can do
|
| cbAccounts.Item s.Add(AcctArray (j,1) & " " & AcctArray(j,2) & " " &
| Acctarray(j,6) & " " & AcctArray(j,13) )
|
| but that doesn't accomplish my objectives...
|
|
| Can someone give me a nudge?
|
| Thanx in advance
|
| --
| Jim Shaffer
|
|
Nov 21 '05 #4
Jim,
I was playing with this a little.

Is this Windows Forms or Web Forms?

In Windows Forms, you can bind a list control (ListBox, ComboBox, DataGrid)
to a one-dimensional array, however you cannot bind to a two-dimensional
array. Which is understandable, as the list controls use IList to support
binding. Array implements IList. If you use IList from a one-dimensional
array you get the list of numbers. If you use IList from a two-dimensional
array you get a single list of numbers & not the rows & columns...

Try the following:

Dim values(,) As Integer = {{11, 12}, {21, 22}, {31, 32}}
Dim list As IList = values
For Each item As Object In list
Debug.WriteLine (item)
Next

What values are printed?

The short of it you cannot bind to a two-dimensional array. I would
recommend you convert the two-dimensional array to either a one-dimensional
array, an ArrayList or a DataTable...

Hope this helps
Jay
"Jim Shaffer" <us****@shaffer assoc.com> wrote in message
news:jO******** ************@co mcast.com...
| Perhaps I have the wrong construct, or misunderstand arrays in vb
(2003)....
| I've loaded a two-dimensional array (168 by 28) into memory as AcctArray.
| {Dim AcctArray (500,28) as string...}
|
| The AcctArray is loaded from a Quickbooks table, so there's no intrinsic
| dataset to assign as datasource....
|
| I want to have a combo table (or list table or whatever), currently named
| cbAccounts, that can scroll through and maybe select items in the array. I
| don't want to display all elements, just columns 1,2,6, and 13...
|
| How do I construct this? A combo box is supposed to have as its datasource
| an "array", but I can't seem to accomplish it. I can do
|
| cbAccounts.Item s.Add(AcctArray (j,1) & " " & AcctArray(j,2) & " " &
| Acctarray(j,6) & " " & AcctArray(j,13) )
|
| but that doesn't accomplish my objectives...
|
|
| Can someone give me a nudge?
|
| Thanx in advance
|
| --
| Jim Shaffer
|
|
Nov 21 '05 #5

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

Similar topics

4
1298
by: Rod | last post by:
I have an Access database with the 3 fields in , , I create a dataset and bind a form to it, no problem. I now want to put in a combo box to search on name. Now I can do this fine if I just use But I want & ", " & to appear in the combo box.
3
14678
by: Shravan | last post by:
Hi, How can I bind DataRow array to ComboBox. I tried setting DataSource -> DataRow Array DisplayMember -> ColumnName But it was showing "System.Data.DataRow" for every item in the combobox instead of fetching the
2
2156
by: SoftWhiteDelgiht | last post by:
Help me. I am obviously stupid! :-) I am just starting out with VB.Net and am trying to do a simple master/detail form with a SqlServer backend. I have created a combo box which is to populate with 'STATUS_DESC' from the STATUS table. This works perfectly. Now I want to populate the form with a row from the Purchase Order table POHEADER and...
0
1512
by: Larry Serflaten | last post by:
I am not sure how many are aware of this sort of data binding, but as it is new to many (classic) VB developers I thought I would post this once just to let people know of its availablility. There are cases where properties of one object is dependant on a property of another object. For a common example, when you bind an ArrayList to a...
0
4787
by: JSantora | last post by:
Essentially, InsertAT is broken! For the past couple of hours, I've been getting this "Parameter name: '-2147483550' is not a valid value for 'index'." error. Apparently, its caused by having manually inserted a row in the table bound to the Combo box. The InsertAt Method of adding a row just does not work. Hope this helps anyone with...
0
1802
by: Roger Odermatt | last post by:
Hello I have binding a class to a DataGridView and this class have a property from another class and this i want binding to a DataGridViewComboBoxColumn. So when i change a item in the Combo and leave this cell, then i have a error (cannot convert String to cCountry). I think the problem is the DataPropertyName in my...
1
9808
by: Monty M. | last post by:
Does anyone know how to perform two way data binding between a combo box and a listview. The listview is bound to a dataset table in code: Binding Bind = new Binding(); DataTable dt; Field_LV.DataContext = dt; Field_LV.SetBinding(ListView.ItemsSourceProperty, Bind);
3
2434
by: Max | last post by:
Hello, I made a windows form with a combo box and 4 text boxes. All 5 objects should get their data from a data set which is populated in the form load method. The combo box has item ids. When the users selects an item from the combo box I'd like the 4 text boxes to get populated with the corresponding item information from the same dataset...
10
5828
by: =?Utf-8?B?UiBSZXllcw==?= | last post by:
Hi, Problem: How can I databind (or put) a SqlServer query's row return of 115,000 items into a ComboBox quickly? Not much longer than a matter of seconds, that is... Scenario: I am rebuilding my company's Access 97 VBA database app. It pulls 115,000 items (of account names) from SqlServer and the data is bound to a single Access 97...
0
7506
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...
0
7782
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, 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. ...
0
8018
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7541
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6123
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5423
isladogs
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...
0
5142
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3545
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2006
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 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.