Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
String multi-dimensional arrays
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 3.0
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01464631
Message ID:
01464668
Views:
56
This message has been marked as the solution to the initial question of the thread.
>Is there any way to easily fill a ListBox from a 2-dimensional array? This is so much easier to do in Visual FoxPro.
>
>I am simply trying to fill a ListBox control in C# (VS2008) from a 2-dimensional array. I would like to only use the 0 column (Far left). The array is used elsewhere as a reference table. But, I'd like to at least fill the ListBox with the first column of data from the array.
>
>My array is filled with data at the class level and is called _crossRefArray. It is declared as follows:
>
>
>namespace ChristophersCarCenter
>{
>    public partial class ChristophersCarCenterForm : Form
>    {
>        string[,] _crossRefArray = new string[9, 4]
>            {   
>                {"PR214","MR43T","RBL8",   "14K22"},
>                {"PR223","R43",  "RJ6",    "14K24"},
>                {"PR224","R43N", "RN4",    "14K30"},
>                {"PR246","R46N", "RN8",    "14K32"},
>                {"PR247","R46TS","RBL17Y", "14K33"},
>                {"PR248","R46TX","RBL12-6","14K35"},
>                {"PR324","S46",  "J11",    "14K38"},
>                {"PR326","SR46E","XEJ8",   "14K40"},
>                {"PR444","47L",  "H12",    "14K44"}
>            };
>        
>        public ChristophersCarCenterForm()
>        {
>            InitializeComponent();
>        }
>
>        private void ChristophersCarCenterForm_Load(object sender, EventArgs e)
>        {
>            CCCListBox.Items.AddRange(_crossRefArray);  // <<<---THIS ISN'T WORKING.
>        }
>
>        private void exitButton_Click(object sender, EventArgs e)
>        {
>            this.Close();
>        }
>    }
>}
>
>
>
>
>It is more simple, I think, to fill a ListBox control in Visual FoxPro than it is in C#.

If you must stick with the array then you could build a single dimension copy for the listbox:
int rows = _crossRefArray.Length / 4;
string[] listboxSource = new string[rows];
for (int i = 0; i < rows; i++)
   {
      listboxSource[i] = _crossRefArray[i, 0];
   }
CCCListBox.DataSource=listboxSource;
But, on the face of it, I'd favour using a list of objects rather than the _crossRefArray - more flexible.....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform