Click here to Skip to main content
15,889,874 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
-Two ListBoxes binded together. The first one to show a directory, and the second to show a subfolder.
-DataGridView to show the .bmp files.
I need to Set only one column called (Blocks) and add a double click event to insert the dwg file.
the red x is shown in datagridview

What I have tried:

private void Form1_Load(object sender, EventArgs e)
{
    listBox1.DataSource = Directory.GetDirectories(rootDirectory).Select(Path.GetFileName).ToList();
    listBox1.SelectedIndexChanged += ListBox1_SelectedIndexChanged;
    listBox2.SelectedIndexChanged += ListBox2_SelectedIndexChanged;

    DataGridViewImageColumn dgvimgcol = new DataGridViewImageColumn();
    dgvimgcol.ImageLayout = DataGridViewImageCellLayout.Stretch;
    dgvimgcol.Width = 250;
    dgvimgcol.HeaderText = "Blocks";
    dgvimgcol.Image = null;
    dataViewImages.RowTemplate.Height = 300;
    dataViewImages.Columns.Add(dgvimgcol);
    dataViewImages.AllowUserToAddRows = false;
    dataViewImages.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
}


private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    // When an item changes in the first listbox, update the second listbox datasource
    var parentDir = Path.Combine(rootDirectory, listBox1.SelectedItem.ToString());
    listBox2.DataSource = Directory.GetDirectories(parentDir).Select(Path.GetFileName).ToList();
}

private void ListBox2_SelectedIndexChanged(object sender, EventArgs e)
{
    // When an item changes in the second listbox, update the datagridview datasource
    var parentDir = Path.Combine(rootDirectory, listBox1.SelectedItem.ToString(),
    listBox2.SelectedItem.ToString());
    dataViewImages.DataSource = Directory.GetFiles(parentDir).Select(f => new { FileName = Path.GetFileName(f) }).ToList();
}
Posted
Updated 10-Dec-17 6:08am

1 solution

C#
<pre>dataViewImages.DataSource = Directory.GetFiles(parentDir).Select(f => new { FileName = Path.GetFileName(f) }).ToList();


Filenames are not images.
 
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