C# Windows From add/remove list [duplicate] - c#

This question already has answers here:
Move selected items from one listbox to another in C# winform
(7 answers)
Closed 7 years ago.
I need to add a "slushbucket" (ServiceNow term) to a C# Windows Form, like the image below, but can't figure out what they're actually called so therefore can't look into how they're created.
Does anyone know what they're called, or better yet how to implement one into a windows form?
I need it to list values from Table1 on the left, then when they are added to the right hand list and the save button is clicked, the values are written to Table2. It would also need to show existing values for Table2 if there are any.

Assuming that this is how the form looks like:
Form1.Png
Here is a simple code that implements your idea as follows:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
for (int i = 6; i <= 10; i++)
{
listBox1.Items.Add("item" + i);
}
for (int i = 1; i <= 5; i++)
{
listBox2.Items.Add("item" + i);
}
}
private void btnSave_Click(object sender, EventArgs e)
{`
if (listBox2.Items.Count >0)
{
string message = "";
foreach (var item in listBox2.Items)
{
message += item + "\n";
}
MessageBox.Show(message);
}`
/// write here the code that save listbox1 and listbox2 items
/// to a text file or a database table and load this text file or
/// the database table inside these two listboxes you could write the
/// code that load data to the two list boxes in the constructor instead
/// of the tow for loops thats i've provided.
}
private void btnAdd_Click(object sender, EventArgs e)
{
try
{
if (!listBox2.Items.Contains(listBox1.SelectedItem))
{
listBox2.Items.Add(listBox1.SelectedItem);
listBox1.Items.Remove(listBox1.SelectedItem);
}
else
{
MessageBox.Show("Item already exists");
}
}
catch (ArgumentNullException exc)
{
MessageBox.Show("Nothing selected to add");
}
}
private void btnRemove_Click(object sender, EventArgs e)
{
try
{
if (!listBox1.Items.Contains(listBox2.SelectedItem))
{
listBox1.Items.Add(listBox2.SelectedItem);
listBox2.Items.Remove(listBox2.SelectedItem);
}
else
{
MessageBox.Show("Item already exists");
}
}
catch (ArgumentNullException exc)
{
MessageBox.Show("Nothing selected to remove");
}
}
}
hope that's what you were looking for :)
Thanks.

This is the image output :
and your code is below. I hope this will be helpful for you.
public partial class Form1 : Form
{
ArrayList Table1;
ArrayList Table2;
bool isSaved = false;
public Form1()
{
InitializeComponent();
Table1 = new ArrayList();
Table2 = new ArrayList();
Table1.Add("Value1");
Table1.Add("Value2");
Table1.Add("Value3");
Table1.Add("Value4");
Table1.Add("Value5");
}
private void populateListBox1() {
for (int i = 0; i < Table1.Count;i++)
{
listBox1.Items.Add(Table1[i]);
}
}
private void Form1_Load(object sender, EventArgs e)
{
populateListBox1();
}
private void refreshListBox1() {
listBox1.Items.Clear();
populateListBox1();
}
private void addToRight() {
try
{
listBox2.Items.Add(Table1[listBox1.SelectedIndex]);
Table1.RemoveAt(listBox1.SelectedIndex);
}
catch
{
MessageBox.Show("You have to select an item first !");
}
refreshListBox1();
}
private void removeFromRight(){
if (isSaved)
{
try
{
listBox1.Items.Add(Table2[listBox2.SelectedIndex]);
Table1.Add(Table2[listBox2.SelectedIndex]);
isSaved = false;
}
catch
{
MessageBox.Show("You have to select an item first !");
isSaved = true;
}
try
{
Table2.RemoveAt(listBox2.SelectedIndex);
listBox2.Items.RemoveAt(listBox2.SelectedIndex);
isSaved = false;
}
catch
{
if(listBox2.Items.Count==0)
MessageBox.Show("This list is an empty list");
isSaved = true;
}
}
else {
MessageBox.Show("You have to click save button first !");
}
}
private void saveToTable2() {
for (int i = 0; i < listBox2.Items.Count;i++)
{
Table2.Add(listBox2.Items[i].ToString());
}
MessageBox.Show("Saved !");
isSaved=true;
}
private void btn_add_Click(object sender, EventArgs e)
{
addToRight();
}
private void btn_save_Click(object sender, EventArgs e)
{
saveToTable2();
}
private void btn_remove_Click(object sender, EventArgs e)
{
removeFromRight();
}
}
}

Related

Passing data between 1 basic class and 2 WPF window

First of all, I'm new to C# and .NET development. I was working on a console app and decided to switch to graphical using WPF. Everything was fine with the console app but I'm having troubles right now. So basically, I have this window:
Window 1
When I click on the "Add Task" button, this new window opens: Window 2. I want to perform a sequential series of save tasks (the app is made to copy directories and eventually encrypt them if the users wants to) and in order to do that, I'm saving all the copy parameters in lists of string in a third class where there's a method to run through them and execute copies.
What I want to do is display all the information the user entered in the Window1 in the datagrid, select the save tasks I want to perform and then call the method that copies when I click on the "Launch Save" button but I can't figure how. I can't retrieve the data stored in the lists in the third class with the Window2 from the Window1, it seems even like I can't store multiple save parameters in the lists I made, only one at a time. Tbh idk what to do, I've been searching for hours for a way to do that but I don't find a clue. I'm pretty sure that the way I'm coding is wrong and that I'm missing some logic/reasoning things that are important (or just a lack of knowledge idk) so that's why I came here asking for help.
Here's the code of the window1:
public partial class NewSave : Window
{
SeqSave sqSv1 = new SeqSave();
public NewSave()
{
InitializeComponent();
List<SeqSave> caracSave = new List<SeqSave>();
if (sqSv1.savedNamesList.Count > 0)
{
for (int i = 0; i < sqSv1.savedNamesList.Count; i++)
{
caracSave.Add(new SeqSave() { SaveTaskName = sqSv1.savedNamesList[i], SourcePath = sqSv1.srcPathList[i], DestinationPath = sqSv1.dstPathList[i], SaveType = sqSv1.saveTypeList[i], Backup = sqSv1.didBackupList[i] });
}
saveListsDisplay.ItemsSource = caracSave;
}
}
private void BusinessSoftware(object sender, RoutedEventArgs e)
{
}
private void AddTask(object sender, RoutedEventArgs e)
{
AddTask aT1 = new AddTask();
aT1.Show();
}
private void saveListsDisplay_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void LaunchSave(object sender, RoutedEventArgs e)
{
//for(int i = 0; i < sqSv1.savedNamesList.Count; i++)
//{
// Console.WriteLine(sqSv1.savedNamesList[i] + "\n"
// + sqSv1.srcPathList[i] + "\n"
// + sqSv1.dstPathList[i] + "\n"
// + sqSv1.saveTypeList[i] + "\n"
// + sqSv1.didBackupList[i]);
//}
sqSv1.launchSave();
}
}
And here's the code of the Window2:
public partial class AddTask : Window
{
List<string> listExtension = new List<string>();
SeqSave sqSv1 = new SeqSave();
public AddTask()
{
InitializeComponent();
}
private void GetSourcePath(object sender, RoutedEventArgs e)
{
FolderBrowserDialog sourcePath = new FolderBrowserDialog();
DialogResult result = sourcePath.ShowDialog();
string strSourcePath = sourcePath.SelectedPath;
sqSv1.srcPathList.Add(strSourcePath);
DirectoryInfo dirInfo = new DirectoryInfo(strSourcePath);
foreach (FileInfo f in dirInfo.GetFiles())
{
if (!listExtension.Contains(f.Extension))
{
listExtension.Add(f.Extension);
}
}
for(int i = 0; i < listExtension.Count; i++)
{
lstB1.Items.Add(listExtension[i]);
}
}
private void GetDestinationPath(object sender, RoutedEventArgs e)
{
FolderBrowserDialog destinationPath = new FolderBrowserDialog();
DialogResult result = destinationPath.ShowDialog();
string strDestinationPath = destinationPath.SelectedPath;
sqSv1.dstPathList.Add(strDestinationPath);
}
private void Encrypt(object sender, RoutedEventArgs e)
{
}
private void Return(object sender, RoutedEventArgs e)
{
}
private void Confirm(object sender, RoutedEventArgs e)
{
sqSv1.savedNamesList.Add(taskNameProject.Text);
if (RadioButton1.IsChecked == true)
{
sqSv1.saveTypeList.Add("1");
}
else if(RadioButton2.IsChecked == true)
{
sqSv1.saveTypeList.Add("2");
}
if (Checkbox1.IsChecked == true)
{
sqSv1.didBackupList.Add(true);
}
else
{
sqSv1.didBackupList.Add(false);
}
MessageBox.Show("Task successfully added.");
this.Visibility = Visibility.Hidden;
}
}
You need to create public properties in your second form. I added public to your code like this. I also added dialog results to both forms.
public partial class AddTask : Window
{
public List<string> ListExtension { get; } = new List<string>();
public SeqSave SqSv1 { get; }= new SeqSave();
public AddTask()
{
InitializeComponent();
}
private void GetSourcePath(object sender, RoutedEventArgs e)
{
FolderBrowserDialog sourcePath = new FolderBrowserDialog();
DialogResult result = sourcePath.ShowDialog();
string strSourcePath = sourcePath.SelectedPath;
SqSv1.srcPathList.Add(strSourcePath);
DirectoryInfo dirInfo = new DirectoryInfo(strSourcePath);
foreach (FileInfo f in dirInfo.GetFiles())
{
if (!ListExtension.Contains(f.Extension))
{
ListExtension.Add(f.Extension);
}
}
for(int i = 0; i < ListExtension.Count; i++)
{
lstB1.Items.Add(ListExtension[i]);
}
}
private void GetDestinationPath(object sender, RoutedEventArgs e)
{
FolderBrowserDialog destinationPath = new FolderBrowserDialog();
DialogResult result = destinationPath.ShowDialog();
string strDestinationPath = destinationPath.SelectedPath;
SqSv1.dstPathList.Add(strDestinationPath);
}
private void Encrypt(object sender, RoutedEventArgs e)
{
}
private void Return(object sender, RoutedEventArgs e)
{
}
private void Confirm(object sender, RoutedEventArgs e)
{
SqSv1.savedNamesList.Add(taskNameProject.Text);
if (RadioButton1.IsChecked == true)
{
SqSv1.saveTypeList.Add("1");
}else if(RadioButton2.IsChecked == true)
{
SqSv1.saveTypeList.Add("2");
}
if (Checkbox1.IsChecked == true)
{
SqSv1.didBackupList.Add(true);
}
else
{
SqSv1.didBackupList.Add(false);
}
MessageBox.Show("Task successfully added.");
this.Close();
DialogResult = DialogResult.OK;
}
}
And then access those in the original form like this:
private void AddTask(object sender, RoutedEventArgs e)
{
AddTask aT1 = new AddTask();
DialogResult results = aT1.ShowDialog();
if(results == DialogResult.OK)
{
List<string> listExt = aT1.ListExtension;
}
}

Accessing a list from a second form and adding user input to the list

I have a list called "studentInfo" and I am trying to allow the user to go to a form I created called "addRecord" and type in a student code and a student mark and once they hit submit the data is then added to the list in form1 and then also the data gets added to the listbox in form1.
I don't know how to go about this since I am new to C# so any guidance will be appreciated.
My list is created like this
public static List<string> studentInfo = new List<string>();
Then once my form1 loads I read in from a CSV file to populate the listbox
private void Form1_Load(object sender, EventArgs e)
{
string lines, studentNumber, studentMark;
StreamReader inputFile;
inputFile = File.OpenText("COM122.csv");
while (!inputFile.EndOfStream)
{
lines = inputFile.ReadLine();
studentInfo = lines.Split(',').ToList();
studentNumber = studentInfo[0];
studentMark = studentInfo[1];
lstMarks.Items.Add(studentNumber + " : " + studentMark);
}
inputFile.Close();
}
I want the user to go to the addRecord form, enter in a student code and student mark, then hit submit and then the program asks the user to confirm that the data they have entered is correct and then the user is directed back to form1 and the data will be in the listbox.
Alrighty, in Form addRecord, we create two properties to hold the data to be retrieved from the main Form. This should only be done if addRecord returns DialogResult.OK. I've added in two buttons, one for cancel and one for OK. These simply set DialogResult to their respective results. The property values for the two values to be returned are also set in the OK button handler:
public partial class addRecord : Form
{
public addRecord()
{
InitializeComponent();
}
private string _Student;
public string Student
{
get
{
return this._Student;
}
}
private string _Score;
public string Score
{
get
{
return this._Score;
}
}
private void btnOK_Click(object sender, EventArgs e)
{
this._Student = this.tbStudent.Text;
this._Score = this.tbScore.Text;
this.DialogResult = DialogResult.OK;
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
}
Now, back in Form1, here is an example of showing addRecord with ShowDialog(), then retrieving the stored values when OK is returned:
public partial class Form1 : Form
{
public static List<string> studentInfo = new List<string>();
// ... other code ...
private void btnAddRecord_Click(object sender, EventArgs e)
{
addRecord frmAddRecord = new addRecord();
if (frmAddRecord.ShowDialog() == DialogResult.OK)
{
studentInfo.Add(frmAddRecord.Student);
studentInfo.Add(frmAddRecord.Score);
lstMarks.Items.Add(frmAddRecord.Student + " : " + frmAddRecord.Score);
}
}
}
--- EDIT ---
Here's a different version of addRecord that doesn't allow you to hit OK until a valid name and a valid score have been entered. Note that the property has been changed to int, and the TextChanged() events have been wired up to ValidateFields(). The OK button is also initially disabled:
public partial class addRecord : Form
{
public addRecord()
{
InitializeComponent();
this.tbStudent.TextChanged += ValidateFields;
this.tbScore.TextChanged += ValidateFields;
btnOK.Enabled = false;
}
private string _Student;
public string Student
{
get
{
return this._Student;
}
}
private int _Score;
public int Score
{
get
{
return this._Score;
}
}
private void ValidateFields(object sender, EventArgs e)
{
bool valid = false; // assume invalid until proven otherwise
// Make sure we have a non-blank name, and a valid mark between 0 and 100:
if (this.tbStudent.Text.Trim().Length > 0)
{
int mark;
if (int.TryParse(this.tbScore.Text, out mark))
{
if (mark >= 0 && mark <= 100)
{
this._Student = this.tbStudent.Text.Trim();
this._Score = mark;
valid = true; // it's all good!
}
}
}
this.btnOK.Enabled = valid;
}
private void btnOK_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
}

C# ListBox syncing with each other

I am trying to make a program that has 3 listBoxes an I need to alphabetize 1 of them but the and the other 2 listboxes info needs to still match the first listBox. As of now I don't have any code for that to show, but I do have my add item code to give a general idea of what I am looking for.
private void addButton_Click(object sender, EventArgs e)
{
if (itemTextBox.Text == "")
MessageBox.Show("Please enter an item to add");
else
groceryListBox.Items.Add(itemTextBox.Text);
itemTextBox.Clear();
countTextBox.Text = groceryListBox.Items.Count.ToString();
//if (quanityListBox.Text == "")
// MessageBox.Show("Please enter an item to add");
//else
quanityListBox.Items.Add(quanityTextBox.Text);
quanityTextBox.Clear();
// countTextBox.Text = quanityListBox.Items.Count.ToString();
//if (priceListBox.Text == "")
// MessageBox.Show("Please enter an item to add");
//else
priceListBox.Items.Add(priceTextBox.Text);
priceTextBox.Clear();
//countTextBox.Text = priceListBox.Items.Count.ToString();
itemTextBox.Focus();
}
private void removeSingleButton_Click(object sender, EventArgs e)
{
if (groceryListBox.SelectedIndex != -1)
{
while(groceryListBox.SelectedItems.Count != 0)
{
groceryListBox.Items.Remove(groceryListBox.SelectedItems[0]);
}
}
else
{
MessageBox.Show("Please Select an item(s) to remove");
}
}
private void saveButton_Click(object sender, EventArgs e)
{
Settings.Default["List1"] = groceryListBox.Items.ToString();
Settings.Default.Save();
}
private void Form1_Load(object sender, EventArgs e)
{
groceryListBox.Text = Settings.Default["List1"].ToString();
}
private void button1_Click(object sender, EventArgs e)
{
groceryListBox.Items.Clear();
}
private void button2_Click(object sender, EventArgs e)
{
groceryListBox.SelectedItems.Clear();
for (int i = groceryListBox.Items.Count - 1; i >= 0; i--)
if (groceryListBox.Items[i].ToString().ToLower().Equals(searchTextBox.Text.ToLower()))
groceryListBox.SetSelected(i, true);
}
private void colorButton_Click(object sender, EventArgs e)
{
groceryListBox.BackColor = Color.DeepSkyBlue;
}
private void containsToolStripMenuItem_Click(object sender, EventArgs e)
{
{
groceryListBox.SelectedItems.Clear();
for (int i = groceryListBox.Items.Count - 1; i >= 0; i--)
if (groceryListBox.Items[i].ToString().ToLower().Contains(searchTextBox.Text.ToLower()))
groceryListBox.SetSelected(i, true);
}
}
private void startsWithToolStripMenuItem_Click(object sender, EventArgs e)
{
{
groceryListBox.SelectedItems.Clear();
for (int i = groceryListBox.Items.Count - 1; i >= 0; i--)
if (groceryListBox.Items[i].ToString().ToLower().StartsWith(searchTextBox.Text.ToLower()))
groceryListBox.SetSelected(i, true);
}
}
private void editToolStripMenuItem_Click(object sender, EventArgs e)
{
editTextBox.Text = groceryListBox.SelectedItem.ToString();
}
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
editTextBox.Paste();
}
private void toolsToolStripMenuItem_Click(object sender, EventArgs e)
{
if (editTextBox.Text == "")
MessageBox.Show("Please enter an item to add");
else
groceryListBox.Items[groceryListBox.SelectedIndex] = editTextBox.Text;
editTextBox.Clear();
countTextBox.Text = groceryListBox.Items.Count.ToString();
}
Any help would be appreciated. Thank you.
Edit.... I figured out how to post screenshot....
At least they allow me a link for now, I guess until my reputation goes up. :-)
This is what I want it to do, if I add an item to the list with quantity and price, and I have multiple items in the list I still want the quantity and price to match that item across from it.
This might help too.....
With the items matching the price and quantity.
If I'm reading your question right, you're looking for an easy way to show the same info between multiple ListBoxs? If so you could try the following:
private List<string> testList = new List<string>();
private void BindTestListData()
{
listBox1.DataSource = null;
listBox1.DataSource = testList;
listBox2.DataSource = null;
listBox2.DataSource = testList;
}
private void button1_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(InputTextBox.Text))
{
testList.Add(InputTextBox.Text);
InputTextBox.Clear();
BindTestListData();
}
}
Feed all your text from your text box into a list instead of adding it directly to the ListBox. Then bind the list to the datasource of your ListBox.
EDIT
Scratch what I had before. I think I better understand your problem now. try something like this:
private struct Item
{
public string Name { get; set; }
public string Quantity { get; set; }
public string Price { get; set; }
}
private List<Item> items = new List<Item>();
private void BindTestListData()
{
listBox1.DataSource = null;
listBox1.DataSource = items;
listBox1.DisplayMember = "Name";
listBox2.DataSource = null;
listBox2.DataSource = items;
listBox2.DisplayMember = "Quantity";
}
private void button1_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(InputTextBox.Text))
{
Item newItem = new Item()
{
Name = InputTextBox.Text,
Quantity = "1",
Price = "$10"
};
items.Add(newItem);
InputTextBox.Clear();
BindTestListData();
}
}
Obviously, the numbers in the button1_click() method are just place holders, but something like this should work.

Can't change TextBox.Text from another form

I have the following C# code in my winform application:
FormPrincipale
private void butFornitore_Click(object sender, EventArgs e)
{
try
{
FormFornitore Dialog = new FormFornitore();
Dialog.ShowDialog();
}
catch(Exception excDial)
{
MessageBox.Show("DIALOG: " + excDial.Message);
}
}
public void getFornitore(string Codice, string Descrizione)
{
this.txtFornitore.Text = Descrizione;
Fornitore = Codice;
}
FormFornitore
private void gridFornitori_DoubleClick(object sender, EventArgs e)
{
try
{
var Codice = gridView2.GetFocusedDataRow()["codconto"].ToString();
var RagSoc = gridView2.GetFocusedDataRow()["dscconto1"].ToString();
FormPrincipale Form = new FormPrincipale();
Form.getFornitore(Codice, RagSoc);
this.Close();
}
catch(Exception excGrid)
{
MessageBox.Show("GRID: " + excGrid.Message);
}
}
The code works (i used breakpoints to check if code was executed) but the Text property of the TextBox doesn't change. I put Modifiers TextBox property on Public, so this is ok too. I'm using Dev Express Grid Control, but i don't think this is the problem. Thank's for help.
To pass the instance of your parent form, you could do something like this:
class FormFornitore: Form
{
protected FormPrincipale parent;
FormFornitore(FormPrincipale parent)
{
this.parent = parent;
}
private void gridFornitori_DoubleClick(object sender, EventArgs e)
{
try
{
var Codice = gridView2.GetFocusedDataRow()["codconto"].ToString();
var RagSoc = gridView2.GetFocusedDataRow()["dscconto1"].ToString();
/// REMOVE THIS FormPrincipale Form = new FormPrincipale();
parent.getFornitore(Codice, RagSoc);
this.Close();
}
catch(Exception excGrid)
{
MessageBox.Show("GRID: " + excGrid.Message);
}
}
}
Then in your "FormPricipale" use it like this
private void butFornitore_Click(object sender, EventArgs e)
{
try
{
FormFornitore Dialog = new FormFornitore(this); // Notice the argument
Dialog.ShowDialog();
}
catch(Exception excDial)
{
MessageBox.Show("DIALOG: " + excDial.Message);
}
}
public void getFornitore(string Codice, string Descrizione)
{
this.txtFornitore.Text = Descrizione;
Fornitore = Codice;
}

c# - Cannot convert from void to list

So, I got kind of stuck over my head while I tried to program something new.
I'm trying to add objectBeer_pluche or objectBeer_Elektro to my OBJberenlijst on the Beren Main form from the details Form, so I can add both instances of 2 classes to the same list.
I'm not even sure this is possible by the way. So, I would like feedback if what I am trying to do is possible to start with. I already figured VOID is not right but I am really clueless here.
This is my main beren.cs form with an OBJberenlist, that's where I try to add objectBeer_pluche or objectBeer_Elektro into it:
public partial class Beren : Form
{
public interface Berenlijst { }
public List<Berenlijst> OBJberenLijst = new List<Berenlijst>();
public Beren()
{
InitializeComponent();
}
private void Beren_Load(object sender, EventArgs e)
{
}
private void BTNToevoegen_Click(object sender, EventArgs e)
{
this.Hide();
Details Details = new Details();
if (Details.ShowDialog(this) == DialogResult.OK)
{
OBJberenLijst.Add(Details.getdetails());
}
Details.Close();
Details.Dispose();
}
public void LijstLaden()
{
foreach(Beer berenobject in OBJberenLijst)
{
LST_beren.Items.Add(berenobject.Naam);
}
}
}
}
from this form called details.cs
public partial class Details : Form
{
public Details()
{
InitializeComponent();
BTN_toevoegen.DialogResult = DialogResult.OK;
BTN_cancel.DialogResult = DialogResult.Cancel;
}
private void Details_Load(object sender, EventArgs e)
{
RDB_pluche.Checked = true;
BTN_ok.Enabled = false;
}
private void RDB_pluche_CheckedChanged(object sender, EventArgs e)
{
PANEL_pluche.Visible = true;
PANEL_elektro.Visible = false;
}
private void RDB_elektro_CheckedChanged(object sender, EventArgs e)
{
PANEL_pluche.Visible = false;
PANEL_elektro.Visible = true;
}
private void BTN_toevoegen_Click(object sender, EventArgs e)
{
open_foto.Filter = "jpg (*.jpg)|*.jpg|bmp(*.bmp)|*.bmp|png(*.png)|*.png";
if (open_foto.ShowDialog() == System.Windows.Forms.DialogResult.OK && open_foto.FileName.Length > 0)
{
TXT_adres.Text = open_foto.FileName;
PIC_beer.Image = Image.FromFile(open_foto.FileName);
}
}
private void BTN_ok_Click(object sender, EventArgs e)
{
}
public void getdetails()
{
if (RDB_pluche.Enabled == true)
{
Pluche_Beer objectBeer_pluche = new Pluche_Beer(TXTNaam_pluche.Text, open_foto.FileName, "(Wasprogramma: " + TXT_wasprogramma.ToString() + " Graden Celsius");
}
else
{
Elektronische_Beer objectBeer_Elektro = new Elektronische_Beer(TXTNaam_elekro.Text, open_foto.FileName, "aantal Batterijen: " + CMBOBatterijen.ToString());
}
}
private void Details_MouseMove(object sender, MouseEventArgs e)
{
foreach (Control c in this.Controls)
{
if (c is TextBox)
{
TextBox textBox = c as TextBox;
if (textBox.Text != string.Empty)
{
BTN_ok.Enabled = true;
}
}
}
}
}
}
The problem is between this line...
OBJberenLijst.Add(Details.getdetails());
...and this line.
public void getdetails()
List.Add() requires an object to add, but getdetails() returns void. You probably want to change getdetails() to something like the following:
public Berenlijst getdetails()
{
if (RDB_pluche.Enabled == true)
{
return new Pluche_Beer(TXTNaam_pluche.Text, open_foto.FileName, "(Wasprogramma: " + TXT_wasprogramma.ToString() + " Graden Celsius");
}
return new Elektronische_Beer(TXTNaam_elekro.Text, open_foto.FileName, "aantal Batterijen: " + CMBOBatterijen.ToString());
}
Hopefully Pluche_Beer and Elektronisch_Beer inherent from Berenlijst. Otherwise you'll have to revise your logic in a broader way.

Categories