Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
error:
can't convert type base DevExpress.XtraEditorslist box controls.selected items collections to system.IO.Directoryinfo

am using devex controls as listboxes
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using DevExpress.XtraEditors;

namespace browserlist
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
            foreach (DriveInfo d1 in DriveInfo.GetDrives())
                drivelist.Items.Add(d1);
        }

        private void drivelist_SelectedIndexChanged(object sender, EventArgs e)
        {
            folderlist.Items.Clear();
            try
            {
                DriveInfo drive = (DriveInfo)drivelist.SelectedItem;
                foreach (DirectoryInfo driveinfo in drive.RootDirectory.GetDirectories())
                    folderlist.Items.Add(driveinfo);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void folderlist_SelectedIndexChanged(object sender, EventArgs e)
        {
            fileslist.Items.Clear();
            DirectoryInfo dir = (DirectoryInfo)folderlist.SelectedItems;
            foreach (FileInfo f1 in dir.GetFiles())
                fileslist.Items.Add(f1);
        }
    }
}
Posted
Updated 9-Feb-12 0:18am
v2

1 solution

Well probably this (drivelist_SelectedIndexChanged) was done in a callback, so on the next callback (folderlist_SelectedIndexChanged) page doesn't know about the binded data on drivelist combobox.

This is a normal behavior. The best thing to do is to use a ASPxHiddenField to store the selected item value (of drivelist) on client side, and then in folderlist_SelectedIndexChanged read the hidden field value instead of folderlist.SelectedItems.

You can also perform the following technique:
http://demos.devexpress.com/ASPxEditorsDemos/ASPxComboBox/ClientAPI.aspx[^]

However, if you search the DevX site:
http://www.devexpress.com/Support/Center/[^]

You will find other user that got in the same problem and the solution.

Cheers
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900