How to Add, Save, Print and Delete Data from DataGridView in C#

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I am welcome to c-sharp tutorial of datagridview these tutorials are all about how you can enhance the data revealed itself such as being able to save delete print reset argue or even exit so let's add new rule and see how it is that is done actually let's say the name is everyone and Molly's in person under okay I said us any problem close and it's a bit of yeah good number there we go I just need to do this click on add new it as you can see we've just add every boss details onto the dell review and even our keep adding yeah and that's really deletes comes in handy okay we have ah details of there are more they don't trust me to do this to select and delete we can even delete multiple multiple roles from the data preview there we go so that is animals teachers right there ok the other thing we can do is we can print that's it guys all we just need to do is click on trade I won't be doing that and we can also save click on save and that will be saved straight on to the spreadsheet there we go goodness [Music] does it so if you want you can say that straight to your wherever you intend to save it that's it right there okay let's close it clothes and can click on exit if you don't want to exit click on level there I can't even click on yes okay so what I'm gonna do now is I'm gonna take you guys straight into V shirt studio 2019 I will prove one of these together on c-sharp so yeah let's do that now guys and welcome back to visual studio 2019 I will now click on create new project ok let's select windows forms application dotnet framework see chef salad that unless click on next once you get to configure your new projects page let's give that project name of it all SCS and the small data great meal underscore save as the name now click on great look it now that our form is ready and now women define the size of the phone last week that the program if you want to call them by let's go for 700 there we go now the next tip is to part 6 labels and 6 text box on board and 6 book buttons as well by sex it's of those who need six levels let's get the debrief in fest they told us find a degree you are there and those are my buttons moved in here and do that just move them here right then I also need labels will any six of those then I need textbooks there we go so all I'm just gonna do now is to enhance the appearance of this the whole object that I have on board and we can then continue coding so I'm just gonna speed up the whole development of the interface and get back to you guys you know that is how it all looks like now so the next I want to do is let's go back to the tool box I'm going to now hard print document print preview dialog also odd ministry per day will go - bye - rupaul day so click on the menu strip and mistress enter file in there we can enter admin [Music] save friends I can enter NZT that's it they are in here edit and inside edits the center research the lead okay that would do it now all of that is done the first thing I'd like to take care of will be let's take care of the exit double click on exit okay see instead of creating or instead of having a function on the reset button now I'm going to create a function here or a method and these were matter that wouldn't say let's say private void or call it me exits and then topic low versus day now they declare their broken unbearable and download results in course and the verbal is I exit why the data track is dialogue result now let's come down here I exit equals message box dot shape the reason why I am carrying out my exit ladies is the Angel of might end up making a mistake and the system can select from them to confirm who they actually want to welcome for not there now let's enter it name so I call that see revealed the does the name of my project then comma have Anna had some argument and this explained to the first one is going to be message message box button and in there is going to be yes or no then comma message box message box tightened and I'm just forgive that yes I'll give that information and enter a semicolon there so what we actually see in is free Angela to hide a select yes or no and if he s is selected we then use an if statement to Ariel as follows if I exact equals dialog results dot yes dot yes in that case application that exit so if you just enter application that fits it not exit okay interpreter and this is it we always seems to have an error here because I was meant to compare to compare with Nietzsche equal sign they'll go now but I have this method in place I just need to do nice to copy that very method I'll call it right inside my exits remember it says buffing but I clicked on earlier first the metal day parenthesis and I'm gonna repeat exactly the same thing let's go on to the form and here we have my Texas to swamp double pill can make there and it's got indeed so that's why this method is very handy okay so exit is officially taken care of just run it and see how it works alright try out the exit click on that no I don't wanna exit let's try any one of of them yeah exit that's fine so if exit is working now the next one out take care is is every take care of this very hard so look first of all I need the name of my dates of gravy although I do not show you guys how to add all of this information on day to Greenfield ok to others information what I'm gonna do is I'm gonna tell it is just a preview because you guys don't see it wanna delete that and let's go back to choose here but well sir I did not show you to you guys so let's just throw another one day to add those headings so all you need to do is click on this little rectangle there and I'm gonna uncheck their neighbor pardon and they were added him and every delete now then click on add column here to click on the add column and the very first one is my student student ID now add another one you see student IDs day then the other one is going to be first name and so on my so name and we have address date of birth right and finally I'm gonna add a mobile number hey that's how I actually thought they do try to do on board yeah I want other thing that I did is go straight to the property yes time man of the data preview make sure you notice the time line come right down here you see where we have let's see all right here we will have the columns click on columns and they each of those columns you see how narrow they are there so if I come in here selects the very first one so let's go write down we need a column width that's it instead of 100 I'm just gonna make that route 120 and I'll repeat the same thing for the other one 120 Transworld 1:20 and day so the whole width of each of them is now 120 now look at what's gonna happen once I click okay so let's click on OK now and there we can see it's actually fill it up so that's what I want to achieve now but you guys know how to do that that was some air I didn't show you guys how to do that now you know how that is done okay the next thing is will not need to and we now need to double click on this so right inside the admin we need to say it is a great view dot rules dot they and the name of each object that we want to address one student ID dot Tex that's the very first one just been copied add the next one after student ID enter comedy the next one after sister ID is so name a first name exe first name dead and GST Sony being and will have address data better mobile CFC and dress based on GXE beautiful [Music] come to XE man there so I need to do now is enter comedy follow me does it say that's how you add those data straight on to whatever these are you have under sticks box return to little use so let's run in and see ok decision time let's add some information diversity student ID is nuts and the name happens to be poured over address of poor gods date of birth uber number we just need to do now is to click on add all right and that's how it works okay the next thing is let's try and take care of the little can delete columns or even delete all okay after we take care of your set so let's take F delete go straight to the bottom delete I think we have the lady may as well double click on the weight in the case of the delete I'm going to create a function right up here so let's just copy this and just change the names around just it right above that I'm gonna delete all of this and here just call it I delete san'dera double click there an inhale I'll use a 4h before loop so take for each that will be data-role little grid see you room they painted in this data Bri be what dot select selected road they'll go then top column there I will now come down here for Santa curly braces and in they have just end up and said it a green view dot Rose dot remove and what I want you to remove is going to be whatever item I have item dot index so dot Indus means anything selected should be deleted right this that should be out there and that is they remove that would delete whatever have in there that is selected have now copied is copy the name of mine better day tested here and tourism a column and also come right here they wanna have in edit double click on edit and just his thirteenth as well so if I run the system now and let's enter whatever in here and let's click on add so if we select any older unless just click on delete there we go supposing we select more than one rule he turned elite serum that is that is how to delete bottom moves let's try this one out there so the next one is let's take care for reset then I'll come to print and then save now coming to mr. double click on visits so right here also going to create a function here so I will call that very function I wish it cleared of this all of this time this is going to be i visits right in there okay and that is the function I intend to use those are the lines of codes however these very lines of code you looking at will only delete whatever content I have only Kalin's called is inside the delete or the reset I mean it's nothing there and now we also call it in here called artists world there should be a semicolon here entered yep all right I'm gonna run until you guys see what I'm talking about ok let's enter whatever yet and click on art see so if I click on reset they are no never said that what's in here as TR follow those in there okay we can reset this by addressing each individual valid entry GXE and the address the text equals then you just click with the doodads yeah we can do that or we can just use a fall you to take your dance so I'm gonna get rid of that now let's use a folder for that so right inside the metadata crater I'm gonna use a for-loop place this entire break there this this one actually Claire this class is a class the data okay why this other one the one approach that I intend to art now this will clear all data techstops right so first entre and devil using this girl fall look at that okay that should collect the data so the data harm on the text box okay I'll play all textbooks data yeah okay so have a good look at those lines of codes this flares the data on all of the text box widest reclaim the data I have on all the data grieve yourself right so let's run it and see how it all looks like yes right now okay guys let's try clouds days this function salmon run it now let's see they enter whatever in here okay odd unless reset the whole system there we go reset works that's fine so hard works reset work delete works flawlessly for us to take your nice print and save you that now let's go to print double click on print okay right inside print both and I'm going to enter this variable I'm going to call it height equals data avid a to review one dot right enjoy a semicolon the next thing I'm going to do now is I'm gonna dance a dated will be one dot height equals data review one dot Rho pounds we'll count so I would then say let's multiply that by day to believe in one must plan - I did we v1 dot root now the rule template.dot height I'd say multiply that by two [Music] now the next thing is I will now use a bitmap let's say beaten up as an object that I intend to created course bitmap and this bitmap without disagree and get data review dot with Calma better grevioux dot heights as copied asunder stamp engineer [Music] and disabilities today if you guys can notice we'll have an arrow here just because I haven't declared this mine data types I'm gonna say big map it was beat map entire column down to see the arrows all right so let's come down here so all I'm now going to do is just have the data leave you to draw out the bitmap then that is that taken care of okay take a good look at it but it's still not doing a walk because we have to print it out using the print dialog so double click on the print back dialogue and India Greece enter adult graphic okay we say that's draw and that is going to be draw image Leslie our image I was wish whatever haven't beatmap I said the coordinate to zero by zero close up they they so - you actually print that should print now so if I run it that anti-whaling here now odd let's click on print okay it's not working you know why because my friend dialogue was meant to our cows made two sets the document updated of this print dialogue to print documents yay okay look at that you must say this print preview download you see where we have del random must be print document one that's the objetive so let's try it again now click on print there we go is working how I want it's a little bit slow there we go as its we see that all you need to do is heat and bring both in there they now closer that is fine and finally what is left for us to take Jeff now is the Save button without Rick on the save okay before we plant three kill this save I'm going to need the Microsoft Office in China but Pareto for the Excel so we have to go well to go to the project right here click on project and let's click on add reference once that is ready does it add reference wait for that now that is references here beneath the extensions click on extensions why would I need Microsoft Office interoperate oh right here look at it Microsoft Office inter Opie operator I believe that is the right there make sure is selected and click on OK they're ready so the next to you do is right inside the Save button double click on that and enter in following lines of codes or we can even create because I have to save I have one here and I also have another one okay so let's create the function right underneath it so I'm going to call that function private what I see the okay then I'm gonna have to import the following Microsoft that sell properties they would go they now the next now want to do is so right underneath here enter the following lines of codes there we will have a good look at that check this look at Matt function the I save function - here number of colonies I save right inside the button to double click on the Save button to save but then there's kondalian yeah is that in there but I'm gonna repeat exactly the same thing here don't click on that and paste that anyway [Music] as for the print say the prints the lines have code for print I did nuts then Tom one for the one on the menu so I'm gonna copy all of this that is the problem coming here double click on this and please little urgently I'm missing a semicolon game I should be missed semicolon anything as well right okay that is a save method or function so I believe I'm finished now so let's run it and see how this can work okay guys decision time let's enter some data in there and see if we can save it so let's assume the student ID is there and name the name is Kingsley she's me hardly impress Johnstown did a bit and telephone number they click on add there we go and let's see if we can save to save so the old idea is to be able to save unto Excel now the system is just starting there we go guys yes we are able to save record and just let for you if you wanna save it onto your own designated area you can do that so I'm just gonna close that yeah you don't need it right we can also delete everything or deletes columns actually or delete rows there we go and delete multiple rows and so on we can reset and add more data so guys with that I'm gonna call it the end of this very very beautiful tutorial and I'll see you guys shortly please do subscribe and bye for now
Info
Channel: DJ Oamen
Views: 10,742
Rating: 4.9148936 out of 5
Keywords: How to Add, Save, Print and Delete Data from DataGridView in C#, rint and Delete Data from DataGridView in C#, Old Town Road, Anthony Joshua, Visual Basic.Net, C#, Visual Studio 2019, Visual C#, Visual C++, Python, C# Project
Id: Ma_sgNYkMDs
Channel Id: undefined
Length: 34min 15sec (2055 seconds)
Published: Sun May 26 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.