Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 25th, 2008, 04:31 AM
Authorized User
 
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default problems with Arraylist of DateTime

Hallo

I've got problems to adding the Items of my list of DateTime objects


I've got these error messages:

Error 4 The best overloaded method match for 'System.Windows.Forms.ListBox.ObjectCollection.Add Range(System.Windows.Forms.ListBox.ObjectCollectio n)' has some invalid arguments
Error 5 Argument '1': cannot convert from 'System.DateTime[]' to 'System.Windows.Forms.ListBox.ObjectCollection'




from the class:
public DateTime[] datoer_GetAllDatoSublist()
            {
                return sublistNavne.ToArray();

            }
From the windows form:
 private void button8_Click(object sender, EventArgs e)
        {
            Reservering r1 = new Reservering("silas", new DateTime(2008, 04, 22));
            Reservering r2 = new Reservering("kurt", new DateTime(2008, 04, 23));
            Reservering r3 = new Reservering("Peter", new DateTime(2008, 04, 24));
            Flaske f1 = new Flaske(r1, "ok", 43);
            f1.addReservartion(r2);
            f1.addReservartion(r3);

            f1.datoer_makeDatoSublist("kurt");

          //this is the problem. AddRange
            listBox2.Items.AddRange(f1.datoer_GetAllDatoSublis t());


        }














this is the list
  public List<DateTime> sublistNavne = new List<DateTime>();

            public DateTime[] datoer_makeDatoSublist(string navn)
           {
               foreach (Reservering en_reservering in reserveringsliste)

                   if (en_reservering.PropertyReserveringsnavn == navn)


                   {
                       sublistNavne.Add(en_reservering.PropertyDato);

                   }

               return sublistNavne.ToArray();
           }

 
Old April 25th, 2008, 04:42 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I'm not 100% but can you try changing it to this and see if that works:

listBox2.Items.AddRange((DateTime[])f1.datoer_GetAllDatoSublist());

/- Sam Judson : Wrox Technical Editor -/
 
Old April 26th, 2008, 04:28 AM
Authorized User
 
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your replay.. but it did not work.. But I found this solution, by using the LINQ listBox2.Items.AddRange(f1.datoer_GetAllDatoSublis t().Cast<object>().ToArray());

Greetings
Silas





Similar Threads
Thread Thread Starter Forum Replies Last Post
ArrayList Mogg-Way C# 2005 5 February 12th, 2008 04:05 PM
Return an arraylist Morrislgn VB.NET 2002/2003 Basics 1 March 24th, 2006 04:42 AM
Help with an arraylist crazy-nun General .NET 4 July 14th, 2005 03:32 AM
UTC DateTime to Local DateTime r_ganesh76 SQL Server 2000 1 April 4th, 2005 08:21 AM
ArrayList kobystud C# 4 May 25th, 2004 02:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.