When i try to delete an datasource i got an panic, that it can't be deleted. How can i delete that one?
and when first running the prg. it isen't load the added info from the arrayList how am i doing that? it is only loading from the arrayList when i mark an object in the listbox...
thanks...
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ArrayListTest
{
public partial class Form1 : Form
{
//Create an instance of ArrayList class
ArrayList arrList = new ArrayList();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
listBoxCD.SelectedIndex = 0;
//Add items
arrList.Add(new CD { Title = "Title1", Artist = "Artist1", Country = "Country1", Company = "Company1", Year = "Year1" });
arrList.Add(new CD { Title = "Title2", Artist = "Artist2", Country = "Country2", Company = "Company2", Year = "Year2" });
arrList.Add(new CD { Title = "Title3", Artist = "Artist3", Country = "Country3", Company = "Company3", Year = "Year3" });
arrList.Add(new CD { Title = "Title4", Artist = "Artist4", Country = "Country4", Company = "Company4", Year = "Year4" });
//Set no item selected
listBoxCD.SelectedIndex = -1;
}
private void btnAdd_Click(object sender, EventArgs e)
{
if (this.textTitle.Text.Equals(""))
{
MessageBox.Show("You must enter a Title");
this.textTitle.Focus();
}
if (this.textArtist.Text.Equals(""))
{
MessageBox.Show("You must enter a Artist");
this.textArtist.Focus();
}
if (this.textCountry.Text.Equals(""))
{
MessageBox.Show("You must enter a Country");
this.textCountry.Focus();
}
if (this.textCompany.Text.Equals(""))
{
MessageBox.Show("You must enter a Company");
this.textCompany.Focus();
}
if (this.textYear.Text.Equals(""))
{
MessageBox.Show("You must enter a Year");
this.textYear.Focus();
}
listBoxCD.Items.Add(textTitle.Text);
//listBoxCD.Items.Add(textArtist.Text);
//listBoxCD.Items.Add(textCountry.Text);
//listBoxCD.Items.Add(textCompany.Text);
//listBoxCD.Items.Add(textYear.Text);
countCD.Text = String.Format("Current Inventory: {0} Item", this.arrList.Count.ToString());
arrList.Add(new CD { Title = textTitle.Text, Artist = textArtist.Text, Country = textCountry.Text, Company = textCompany.Text, Year = textYear.Text });
}
private void btnRemove_Click(object sender, EventArgs e)
{
if (listBoxCD.SelectedIndex == -1)
{
MessageBox.Show("Please select an item first.", "No item selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
listBoxCD.Items.RemoveAt(listBoxCD.SelectedIndex);
}
}
private void listBoxCD_SelectedIndexChanged(object sender, EventArgs e)
{
//MessageBox.Show(listBoxCD.SelectedIndex.ToString() + "\n" + listBoxCD.GetItemText(listBoxCD.SelectedItem), "listBoxCD_SelectedIndexChanged");
listBoxCD.DataSource = null;
listBoxCD.DataSource = arrList;
}
private void btnClear_Click(object sender, EventArgs e)
{
listBoxCD.Items.Clear();
}
}
}

New Topic/Question
Reply




MultiQuote




|