Rotsey wrote:
The FileName property is spelled/cased correctly
You will notice that my ocde is in ProgressChnaged event
so the listox is to be filled incremently.
Using the DataSource property correctly uses the displaymenber/valuemember
properties.
So why doesn't AddRange work the same????
It does. There must be some other bug. See below.
When I load that form, I get a listbox with the words One, Two, Three,
and Four as the items in it. In .NET 2.0 it seems to work fine anyways.
Chris.
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ProofOfConcept
{
public class Form1 : Form
{
protected class InnerTestObject
{
private string someValue;
public InnerTestObject() : this("") { }
public InnerTestObject(string val)
{
this.someValue = val;
}
public string Jabberwocky
{
get { return this.someValue; }
set { this.someValue = value; }
}
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
listBox1.Items.AddRange(new InnerTestObject[] {
new InnerTestObject("One"),
new InnerTestObject("Two"),
new InnerTestObject("Three"),
new InnerTestObject("Four")});
listBox1.DisplayMember = "Jabberwocky";
}
private ListBox listBox1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.listBox1 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// listBox1
//
this.listBox1.FormattingEnabled = true;
this.listBox1.Location = new System.Drawing.Point(12, 12);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(120, 95);
this.listBox1.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(251, 238);
this.Controls.Add(this.listBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
}
}