Deleting data from a list from a second formCross-thread operation not valid: Control accessed from a thread other than the thread it was created onCreating a comma separated list from IList<string> or IEnumerable<string>Get int value from enum in C#How to Sort a List<T> by a property in the objectCalling new Form by clicking an item on the ListBoxhow to get data from CSV file to form on NumericUpdown controls in C#Why not inherit from List<T>?cannot refresh listbox from listRename a file listed on C# windows form listBoxAccessing a list from a second form and adding user input to the list

What happens to unproductive professors?

Can you cast the Shape Water spell without an existing obvious pool of water?

How does Kaya's Ghostform interact with Elenda, the Dusk Rose?

Generalized Behrend version for Grothendieck-Lefschetz trace formula

How many Jimmys can fit?

Found and corrected a mistake on someone's else paper -- praxis?

Number of states in taxi environment (Dietterich 2000)

Password Hashing Security Using Scrypt & Argon2

When do flights get cancelled due to fog?

VHF 50 Ω Antenna Over 75 Ω TV Coax

Simplicial manifold associated to Lie groupoid

Correct notation for guitar fingerstyle

What could cause the sea level to massively decrease?

No Torah = Revert to Nothingness?

Need a non-volatile memory IC with near unlimited read/write operations capability

Is this Cambridge Dictionary example of "felicitate" valid?

What was the nature of the known bugs in the Space Shuttle software?

Write a function

Category-theoretic treatment of diffs, patches and merging?

Is there a method for differentiating informative comments from commented out code?

How to evaluate the performance of open source solver?

Party going through airport security at separate times?

When I press the space bar it deletes the letters in front of it

Estimates on number of topologies on a finite set



Deleting data from a list from a second form


Cross-thread operation not valid: Control accessed from a thread other than the thread it was created onCreating a comma separated list from IList<string> or IEnumerable<string>Get int value from enum in C#How to Sort a List<T> by a property in the objectCalling new Form by clicking an item on the ListBoxhow to get data from CSV file to form on NumericUpdown controls in C#Why not inherit from List<T>?cannot refresh listbox from listRename a file listed on C# windows form listBoxAccessing a list from a second form and adding user input to the list






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I have a form that where I read in a csv file containing student information, the file has two columns StudentNumber and Mark. I want to allow the user to click a button on the first form to then go to another form called deleteRecord On this form the user will type in a StudentNumber and a Mark and the record that corresponds with them two pieces of information will be delete from the list.



Since I am new to C# I am not sure on how to go about this so any help will be appreciated.



My list:



public static List<string> studentInfo = new List<string>();



I store all the data from that list in a listbox called lstMarks



I want to also confirm to the user that the record was deleted successfully.










share|improve this question
























  • It's always only two columns, student number and their Mark?

    – Jlalonde
    Mar 25 at 23:37











  • yes there is only 2 collumns

    – Darren_D19
    Mar 25 at 23:49

















2















I have a form that where I read in a csv file containing student information, the file has two columns StudentNumber and Mark. I want to allow the user to click a button on the first form to then go to another form called deleteRecord On this form the user will type in a StudentNumber and a Mark and the record that corresponds with them two pieces of information will be delete from the list.



Since I am new to C# I am not sure on how to go about this so any help will be appreciated.



My list:



public static List<string> studentInfo = new List<string>();



I store all the data from that list in a listbox called lstMarks



I want to also confirm to the user that the record was deleted successfully.










share|improve this question
























  • It's always only two columns, student number and their Mark?

    – Jlalonde
    Mar 25 at 23:37











  • yes there is only 2 collumns

    – Darren_D19
    Mar 25 at 23:49













2












2








2








I have a form that where I read in a csv file containing student information, the file has two columns StudentNumber and Mark. I want to allow the user to click a button on the first form to then go to another form called deleteRecord On this form the user will type in a StudentNumber and a Mark and the record that corresponds with them two pieces of information will be delete from the list.



Since I am new to C# I am not sure on how to go about this so any help will be appreciated.



My list:



public static List<string> studentInfo = new List<string>();



I store all the data from that list in a listbox called lstMarks



I want to also confirm to the user that the record was deleted successfully.










share|improve this question
















I have a form that where I read in a csv file containing student information, the file has two columns StudentNumber and Mark. I want to allow the user to click a button on the first form to then go to another form called deleteRecord On this form the user will type in a StudentNumber and a Mark and the record that corresponds with them two pieces of information will be delete from the list.



Since I am new to C# I am not sure on how to go about this so any help will be appreciated.



My list:



public static List<string> studentInfo = new List<string>();



I store all the data from that list in a listbox called lstMarks



I want to also confirm to the user that the record was deleted successfully.







c#






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 0:23









Jlalonde

4032 silver badges13 bronze badges




4032 silver badges13 bronze badges










asked Mar 25 at 23:12









Darren_D19Darren_D19

205 bronze badges




205 bronze badges












  • It's always only two columns, student number and their Mark?

    – Jlalonde
    Mar 25 at 23:37











  • yes there is only 2 collumns

    – Darren_D19
    Mar 25 at 23:49

















  • It's always only two columns, student number and their Mark?

    – Jlalonde
    Mar 25 at 23:37











  • yes there is only 2 collumns

    – Darren_D19
    Mar 25 at 23:49
















It's always only two columns, student number and their Mark?

– Jlalonde
Mar 25 at 23:37





It's always only two columns, student number and their Mark?

– Jlalonde
Mar 25 at 23:37













yes there is only 2 collumns

– Darren_D19
Mar 25 at 23:49





yes there is only 2 collumns

– Darren_D19
Mar 25 at 23:49












1 Answer
1






active

oldest

votes


















1














If all the data is stored in the list, simply use LINQ and add a number for each student in the list for the index.



First you'll need to create a class and (I recommend it) put it in a folder.
How it looks.



Then you'll have to put the propreties in the class:



public class Student

public int StudentNumber get; set;
public int Mark get; set;
public int Index get; set;



Now add another class with the list:



partial class MainWindow : Window
{
private List<Student> _studentInfo = new List<Student>()

new Student() Index = 0, StudentNumber = 0, Mark = 0
// ...



And then add using at the top of your code of deleteRecord and the name of the folder and the two classes:



using ExampleFolder.Class;


You'll need to call your Student class to be able to modify the StudentNumber and Mark and Index.



Student studentInfo = new Student();


 int iIndex = 0;

var req = from info in studentInfo
where info.StudentNumber == txtStudentNumber && info.Mark == txtMarks
select info.Index; // Starts with 0 for the first student in the list
foreach(var num in req)

iIndex = num;

studentInfo.Remove(studentInfo[iIndex]);

MessageBox.Show("Deleted!");





share|improve this answer

























  • From your code, When it get execute, i see only one record get deleted no mater how many records user select. Instead you can put delete inside foreach loop and user have multiple selection at once, it will be much better.

    – Mdyahiya
    Mar 26 at 0:04












  • The best would be making a ListView with all the students and their info and then just click on the one you want to delete and use SelectedIndex and then press a button to delete it.

    – Voxaim
    Mar 26 at 0:06












  • What form would I put this code on? the first form or the deleteRecord form

    – Darren_D19
    Mar 26 at 0:12











  • From the place the user clicks or confirm to delete.

    – Voxaim
    Mar 26 at 0:13











  • I am getting an error "The name studentInfo doesn't exist in the current context" how do I make it so that I can use the list on this form? this goes for txtStudent and txtMarks.

    – Darren_D19
    Mar 26 at 0:20










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55347702%2fdeleting-data-from-a-list-from-a-second-form%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














If all the data is stored in the list, simply use LINQ and add a number for each student in the list for the index.



First you'll need to create a class and (I recommend it) put it in a folder.
How it looks.



Then you'll have to put the propreties in the class:



public class Student

public int StudentNumber get; set;
public int Mark get; set;
public int Index get; set;



Now add another class with the list:



partial class MainWindow : Window
{
private List<Student> _studentInfo = new List<Student>()

new Student() Index = 0, StudentNumber = 0, Mark = 0
// ...



And then add using at the top of your code of deleteRecord and the name of the folder and the two classes:



using ExampleFolder.Class;


You'll need to call your Student class to be able to modify the StudentNumber and Mark and Index.



Student studentInfo = new Student();


 int iIndex = 0;

var req = from info in studentInfo
where info.StudentNumber == txtStudentNumber && info.Mark == txtMarks
select info.Index; // Starts with 0 for the first student in the list
foreach(var num in req)

iIndex = num;

studentInfo.Remove(studentInfo[iIndex]);

MessageBox.Show("Deleted!");





share|improve this answer

























  • From your code, When it get execute, i see only one record get deleted no mater how many records user select. Instead you can put delete inside foreach loop and user have multiple selection at once, it will be much better.

    – Mdyahiya
    Mar 26 at 0:04












  • The best would be making a ListView with all the students and their info and then just click on the one you want to delete and use SelectedIndex and then press a button to delete it.

    – Voxaim
    Mar 26 at 0:06












  • What form would I put this code on? the first form or the deleteRecord form

    – Darren_D19
    Mar 26 at 0:12











  • From the place the user clicks or confirm to delete.

    – Voxaim
    Mar 26 at 0:13











  • I am getting an error "The name studentInfo doesn't exist in the current context" how do I make it so that I can use the list on this form? this goes for txtStudent and txtMarks.

    – Darren_D19
    Mar 26 at 0:20















1














If all the data is stored in the list, simply use LINQ and add a number for each student in the list for the index.



First you'll need to create a class and (I recommend it) put it in a folder.
How it looks.



Then you'll have to put the propreties in the class:



public class Student

public int StudentNumber get; set;
public int Mark get; set;
public int Index get; set;



Now add another class with the list:



partial class MainWindow : Window
{
private List<Student> _studentInfo = new List<Student>()

new Student() Index = 0, StudentNumber = 0, Mark = 0
// ...



And then add using at the top of your code of deleteRecord and the name of the folder and the two classes:



using ExampleFolder.Class;


You'll need to call your Student class to be able to modify the StudentNumber and Mark and Index.



Student studentInfo = new Student();


 int iIndex = 0;

var req = from info in studentInfo
where info.StudentNumber == txtStudentNumber && info.Mark == txtMarks
select info.Index; // Starts with 0 for the first student in the list
foreach(var num in req)

iIndex = num;

studentInfo.Remove(studentInfo[iIndex]);

MessageBox.Show("Deleted!");





share|improve this answer

























  • From your code, When it get execute, i see only one record get deleted no mater how many records user select. Instead you can put delete inside foreach loop and user have multiple selection at once, it will be much better.

    – Mdyahiya
    Mar 26 at 0:04












  • The best would be making a ListView with all the students and their info and then just click on the one you want to delete and use SelectedIndex and then press a button to delete it.

    – Voxaim
    Mar 26 at 0:06












  • What form would I put this code on? the first form or the deleteRecord form

    – Darren_D19
    Mar 26 at 0:12











  • From the place the user clicks or confirm to delete.

    – Voxaim
    Mar 26 at 0:13











  • I am getting an error "The name studentInfo doesn't exist in the current context" how do I make it so that I can use the list on this form? this goes for txtStudent and txtMarks.

    – Darren_D19
    Mar 26 at 0:20













1












1








1







If all the data is stored in the list, simply use LINQ and add a number for each student in the list for the index.



First you'll need to create a class and (I recommend it) put it in a folder.
How it looks.



Then you'll have to put the propreties in the class:



public class Student

public int StudentNumber get; set;
public int Mark get; set;
public int Index get; set;



Now add another class with the list:



partial class MainWindow : Window
{
private List<Student> _studentInfo = new List<Student>()

new Student() Index = 0, StudentNumber = 0, Mark = 0
// ...



And then add using at the top of your code of deleteRecord and the name of the folder and the two classes:



using ExampleFolder.Class;


You'll need to call your Student class to be able to modify the StudentNumber and Mark and Index.



Student studentInfo = new Student();


 int iIndex = 0;

var req = from info in studentInfo
where info.StudentNumber == txtStudentNumber && info.Mark == txtMarks
select info.Index; // Starts with 0 for the first student in the list
foreach(var num in req)

iIndex = num;

studentInfo.Remove(studentInfo[iIndex]);

MessageBox.Show("Deleted!");





share|improve this answer















If all the data is stored in the list, simply use LINQ and add a number for each student in the list for the index.



First you'll need to create a class and (I recommend it) put it in a folder.
How it looks.



Then you'll have to put the propreties in the class:



public class Student

public int StudentNumber get; set;
public int Mark get; set;
public int Index get; set;



Now add another class with the list:



partial class MainWindow : Window
{
private List<Student> _studentInfo = new List<Student>()

new Student() Index = 0, StudentNumber = 0, Mark = 0
// ...



And then add using at the top of your code of deleteRecord and the name of the folder and the two classes:



using ExampleFolder.Class;


You'll need to call your Student class to be able to modify the StudentNumber and Mark and Index.



Student studentInfo = new Student();


 int iIndex = 0;

var req = from info in studentInfo
where info.StudentNumber == txtStudentNumber && info.Mark == txtMarks
select info.Index; // Starts with 0 for the first student in the list
foreach(var num in req)

iIndex = num;

studentInfo.Remove(studentInfo[iIndex]);

MessageBox.Show("Deleted!");






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 26 at 0:37

























answered Mar 25 at 23:59









VoxaimVoxaim

554 bronze badges




554 bronze badges












  • From your code, When it get execute, i see only one record get deleted no mater how many records user select. Instead you can put delete inside foreach loop and user have multiple selection at once, it will be much better.

    – Mdyahiya
    Mar 26 at 0:04












  • The best would be making a ListView with all the students and their info and then just click on the one you want to delete and use SelectedIndex and then press a button to delete it.

    – Voxaim
    Mar 26 at 0:06












  • What form would I put this code on? the first form or the deleteRecord form

    – Darren_D19
    Mar 26 at 0:12











  • From the place the user clicks or confirm to delete.

    – Voxaim
    Mar 26 at 0:13











  • I am getting an error "The name studentInfo doesn't exist in the current context" how do I make it so that I can use the list on this form? this goes for txtStudent and txtMarks.

    – Darren_D19
    Mar 26 at 0:20

















  • From your code, When it get execute, i see only one record get deleted no mater how many records user select. Instead you can put delete inside foreach loop and user have multiple selection at once, it will be much better.

    – Mdyahiya
    Mar 26 at 0:04












  • The best would be making a ListView with all the students and their info and then just click on the one you want to delete and use SelectedIndex and then press a button to delete it.

    – Voxaim
    Mar 26 at 0:06












  • What form would I put this code on? the first form or the deleteRecord form

    – Darren_D19
    Mar 26 at 0:12











  • From the place the user clicks or confirm to delete.

    – Voxaim
    Mar 26 at 0:13











  • I am getting an error "The name studentInfo doesn't exist in the current context" how do I make it so that I can use the list on this form? this goes for txtStudent and txtMarks.

    – Darren_D19
    Mar 26 at 0:20
















From your code, When it get execute, i see only one record get deleted no mater how many records user select. Instead you can put delete inside foreach loop and user have multiple selection at once, it will be much better.

– Mdyahiya
Mar 26 at 0:04






From your code, When it get execute, i see only one record get deleted no mater how many records user select. Instead you can put delete inside foreach loop and user have multiple selection at once, it will be much better.

– Mdyahiya
Mar 26 at 0:04














The best would be making a ListView with all the students and their info and then just click on the one you want to delete and use SelectedIndex and then press a button to delete it.

– Voxaim
Mar 26 at 0:06






The best would be making a ListView with all the students and their info and then just click on the one you want to delete and use SelectedIndex and then press a button to delete it.

– Voxaim
Mar 26 at 0:06














What form would I put this code on? the first form or the deleteRecord form

– Darren_D19
Mar 26 at 0:12





What form would I put this code on? the first form or the deleteRecord form

– Darren_D19
Mar 26 at 0:12













From the place the user clicks or confirm to delete.

– Voxaim
Mar 26 at 0:13





From the place the user clicks or confirm to delete.

– Voxaim
Mar 26 at 0:13













I am getting an error "The name studentInfo doesn't exist in the current context" how do I make it so that I can use the list on this form? this goes for txtStudent and txtMarks.

– Darren_D19
Mar 26 at 0:20





I am getting an error "The name studentInfo doesn't exist in the current context" how do I make it so that I can use the list on this form? this goes for txtStudent and txtMarks.

– Darren_D19
Mar 26 at 0:20








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55347702%2fdeleting-data-from-a-list-from-a-second-form%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현