1 00:00:00,880 --> 00:00:06,610 In this video we're going to start designing a screen to help us manage our vehicle listings so lets 2 00:00:06,610 --> 00:00:11,480 us just start our application and refresh ourselves with what we've done so far. 3 00:00:11,770 --> 00:00:17,820 And we have many listing here that allows us to add remove edit and view listings. 4 00:00:17,830 --> 00:00:20,650 So I'm actually just going to do all of that from. 5 00:00:20,800 --> 00:00:22,500 Well one window. 6 00:00:22,630 --> 00:00:23,360 And you know. 7 00:00:23,360 --> 00:00:26,470 Case by case you probably design something else. 8 00:00:26,470 --> 00:00:33,370 So I'm going to modify this entire listing or this entire menu strip and just have mileage vehicle listing 9 00:00:33,880 --> 00:00:41,140 someone to remove all of the child options of that menu and I can just click and delete. 10 00:00:41,140 --> 00:00:46,720 So when I click that one I did select that I could just press delete and it will actually just remove 11 00:00:46,720 --> 00:00:47,590 that menu item. 12 00:00:47,590 --> 00:00:49,860 So that's so you can go about removing them. 13 00:00:49,860 --> 00:00:50,110 Right. 14 00:00:50,740 --> 00:00:56,260 So I want one that says manage vehicle listing now when I click it I'm going to launch a new form that's 15 00:00:56,260 --> 00:01:03,140 a mean to see all the vehicles in the database and then perform the crowd activities from there. 16 00:01:03,140 --> 00:01:04,920 So I'm going to do everything from one window. 17 00:01:04,930 --> 00:01:11,020 So firstly I want to double click and do the Click event on that button. 18 00:01:11,020 --> 00:01:13,580 So there are a number of activities that need to be done. 19 00:01:13,600 --> 00:01:18,110 And I agree it takes and they don't need to be done in any particular order. 20 00:01:18,370 --> 00:01:23,200 So I'm creating the Click event but I'm not going to put anything in the click event because well the 21 00:01:23,230 --> 00:01:28,840 ultimate reason for that given would be to launch the window and I haven't yet created that farm right. 22 00:01:28,840 --> 00:01:31,650 So yes I have the tick given what I need to create the form. 23 00:01:31,660 --> 00:01:37,090 So in no particular order I have stuff to do I'm just saying that to say that you don't do one thing 24 00:01:37,090 --> 00:01:44,120 that the of a strict order of or series of activities that have to be performed in a particular order. 25 00:01:44,110 --> 00:01:49,690 Right so of the click event already we can come up to that but I'm went to regulate my project go to 26 00:01:49,690 --> 00:01:52,210 add say new item. 27 00:01:52,210 --> 00:02:01,340 And once again I'm creating a blank form and then this time I'm going to call it manage vehicle listing. 28 00:02:01,390 --> 00:02:01,710 All right. 29 00:02:02,140 --> 00:02:08,320 So my form is manage vehicle listing I can spend some time doing some cosmetic changes where I'm going 30 00:02:08,320 --> 00:02:12,220 to meet the text in the title bar not look. 31 00:02:12,280 --> 00:02:15,610 So you know programming will look like. 32 00:02:15,640 --> 00:02:16,000 All right. 33 00:02:16,000 --> 00:02:21,900 So manage vehicle listing and then I'm going to start looking at some new controls. 34 00:02:21,910 --> 00:02:25,130 And the first new control would be the grid view control. 35 00:02:25,150 --> 00:02:32,320 So in my tool box I'm going to go into the subcategory data and then I'd want to see one that is data 36 00:02:32,350 --> 00:02:39,380 grid view so data grid view displays rows and columns of data in a grid that you can customize. 37 00:02:39,380 --> 00:02:39,660 All right. 38 00:02:39,670 --> 00:02:42,140 So that is what we're going to drive over. 39 00:02:42,220 --> 00:02:46,960 So I drove over that data grid view and you notice that it's just this big green box. 40 00:02:46,960 --> 00:02:50,960 So I'm just going to expand this grid box to a certain extent. 41 00:02:51,070 --> 00:02:59,590 If I use that current I get by that menu and I can edit columns and columns you know enable it edit 42 00:02:59,620 --> 00:03:07,720 delete and add addition functions to the grid if I want I can also dock in the containers if I'm not 43 00:03:07,720 --> 00:03:10,690 going to Gunton and fills the entire container right. 44 00:03:10,750 --> 00:03:16,090 That's not necessarily what I want because I'm going to put the entire label at the top to say manage 45 00:03:16,090 --> 00:03:17,110 vehicle this. 46 00:03:17,290 --> 00:03:20,450 And I'm also going to put in some other things in here. 47 00:03:20,470 --> 00:03:25,360 So you know maybe it starts off with one idea of what you want to do and then you realize that oh but 48 00:03:25,360 --> 00:03:27,850 you don't have to do it that way you could do it another way. 49 00:03:28,330 --> 00:03:34,830 Sometimes that happens so let's start off by not having it docked and then going to bring over a label. 50 00:03:34,840 --> 00:03:39,120 So I have a label in add our entire record already. 51 00:03:39,120 --> 00:03:44,830 So instead of going and trying to design a brand new label I'm just going to copy this going back over 52 00:03:44,830 --> 00:03:51,550 to my new form paste it make sure I position it and I'm going to change the text I go to properties 53 00:03:51,580 --> 00:03:58,010 change it takes and this one is manage vehicle listing all right. 54 00:03:58,130 --> 00:04:01,610 So this reposition it accordingly. 55 00:04:01,610 --> 00:04:07,340 All right so our new window for managing the vehicle listing no most important the most important parts 56 00:04:07,340 --> 00:04:14,780 of this is our grid view saw a grid view will give us like a tabular representation of whatever data 57 00:04:14,780 --> 00:04:16,670 we tell it that we want to see. 58 00:04:16,670 --> 00:04:17,690 Right. 59 00:04:17,690 --> 00:04:23,360 So you can think of Excel or even in the database when we did a select star from a table that we saw. 60 00:04:23,360 --> 00:04:26,380 We notice that we get that tabular representation. 61 00:04:26,390 --> 00:04:29,060 That's exactly what that data grid view of those us to do. 62 00:04:29,060 --> 00:04:34,940 So the first thing that we do with these what I call them more essential controls because a label is 63 00:04:34,940 --> 00:04:36,860 essential but not that much. 64 00:04:36,860 --> 00:04:39,900 But I want to know the name of my grid view right. 65 00:04:40,280 --> 00:04:45,410 So I go to properties of the thinking grid view and you can take some time and look at the properties 66 00:04:45,410 --> 00:04:53,060 and realize that these properties whatever control their different properties and of course each control 67 00:04:53,060 --> 00:04:54,660 is unique in its own right. 68 00:04:54,740 --> 00:04:59,560 But the one the one common property is going to be name. 69 00:04:59,720 --> 00:05:06,860 And I don't want my data grid view to because it's a grid view someone to call this dv you know are 70 00:05:07,130 --> 00:05:08,510 GV grid view. 71 00:05:08,540 --> 00:05:09,250 Right. 72 00:05:09,320 --> 00:05:17,770 And this is car these star vehicles which are row on so remember my prefix and then the name of whatever 73 00:05:18,070 --> 00:05:20,590 it is that this control is for. 74 00:05:20,620 --> 00:05:23,040 So a grid view for vehicle lists. 75 00:05:23,160 --> 00:05:32,590 Then I'm going to set up this farm that when it loads I run a query for the vehicles and I put that 76 00:05:32,590 --> 00:05:37,570 data are the data that's going back from that query inside of this grid view. 77 00:05:37,570 --> 00:05:37,960 Right. 78 00:05:38,440 --> 00:05:45,330 So remember we did something similar to that when we were looking at launching our car or was it our 79 00:05:45,340 --> 00:05:53,110 ad or into the record form when we wanted to make sure that our combo box had all the data it needed 80 00:05:53,110 --> 00:05:54,790 from the listing of cars. 81 00:05:54,790 --> 00:05:55,030 Right. 82 00:05:55,030 --> 00:06:00,340 So in this case you want the grid view to have that same data when the form loads. 83 00:06:00,550 --> 00:06:06,520 So since I wanted to happen when the form loads the when this happens that is the events that I want. 84 00:06:06,550 --> 00:06:12,910 So I'm going to click on the form go over to properties the lightning bolt and I'm seeing that when 85 00:06:12,910 --> 00:06:16,840 the form loads I want this particular thing to happen. 86 00:06:16,850 --> 00:06:22,940 So I'm just going to double click inside the load section and know it's saying okay this is the farm 87 00:06:22,940 --> 00:06:25,190 name on the score load. 88 00:06:25,240 --> 00:06:28,950 So when the farm loads What do I want to happen. 89 00:06:28,960 --> 00:06:34,840 So the next thing I want to do of course is establish a database connection and then I can start earning 90 00:06:34,840 --> 00:06:35,440 my query. 91 00:06:35,470 --> 00:06:43,030 So if you forgot how that works you can go back to the order into the record code file where what we 92 00:06:43,030 --> 00:06:49,250 did was declare an object that represented our connection to the database we initialize it inside of 93 00:06:49,250 --> 00:06:56,760 for constructor and then wherever we needed to access the database we simply called on that object right. 94 00:06:56,860 --> 00:06:58,790 So we're going to follow that same pattern. 95 00:06:58,810 --> 00:07:07,330 So in our new form the first thing I want to do is in the class I'm defining our private and I'm making 96 00:07:07,330 --> 00:07:10,430 it read only that's muscle memory because it doesn't it that's always happens. 97 00:07:10,460 --> 00:07:13,030 So you know you can do it with all the read only. 98 00:07:13,030 --> 00:07:20,770 That's fine but I wanted to be off type car or into entities though if you forgot where this name came 99 00:07:20,770 --> 00:07:21,550 from. 100 00:07:21,550 --> 00:07:25,710 Then in the e d m x file that you would have created for this project. 101 00:07:25,720 --> 00:07:33,220 That's a car into a DB the idea makes in my case but if you have a different name it must be dot e DMX. 102 00:07:33,220 --> 00:07:40,240 You can double click that's use C or D It's a model but when you go to properties you will see entity 103 00:07:40,240 --> 00:07:46,970 country in your name and that is the class type that represents the connection to your database. 104 00:07:46,990 --> 00:07:52,990 All right so if you have forget the name or you are doing one from scratch you just looking at entity 105 00:07:52,990 --> 00:07:57,300 country in your name and whatever name is there that is your data type. 106 00:07:57,450 --> 00:07:58,080 All right. 107 00:07:58,090 --> 00:08:04,820 So back in our new code file for our new form we say a private read only date. 108 00:08:04,900 --> 00:08:05,240 Sorry. 109 00:08:05,270 --> 00:08:11,830 Car Into entities which is our entity contain a name and that I'm going to give it the object name so 110 00:08:12,050 --> 00:08:15,460 visual studio is always making suggestions and that's really cool. 111 00:08:15,490 --> 00:08:24,430 I took one of the additions in the previous form where I said add car and let me find that code quickly. 112 00:08:24,640 --> 00:08:30,280 So in the previous one where I access the database I use the resource through those suggestions. 113 00:08:30,310 --> 00:08:36,460 And that's fine but a lot of the times on the internet you probably see something like context being 114 00:08:36,460 --> 00:08:45,310 used or underscored D.B. The fact is the name of the object is not it's not it's inconsequential to 115 00:08:45,310 --> 00:08:46,670 the functionality. 116 00:08:46,690 --> 00:08:47,020 All right. 117 00:08:47,050 --> 00:08:49,150 So I can name my object anything. 118 00:08:49,180 --> 00:08:52,780 So in this situation I'm going to name it underscored DB. 119 00:08:52,810 --> 00:09:00,000 That being said over I do promote consistency so if you started on one path continued on that path. 120 00:09:00,310 --> 00:09:05,680 If you want to change the path change a path right through your code so don't have underscored D.B. 121 00:09:05,680 --> 00:09:06,330 in this form. 122 00:09:06,610 --> 00:09:13,110 And then car into a record or into entities in another form and then another form a field another way 123 00:09:13,120 --> 00:09:15,100 and you call its contact star X.. 124 00:09:15,160 --> 00:09:19,720 Don't don't do that doesn't have one consistent naming convention. 125 00:09:19,730 --> 00:09:25,630 I'm doing it this way just to show you that whatever you call the object is inconsequential. 126 00:09:25,630 --> 00:09:26,300 All right. 127 00:09:26,300 --> 00:09:32,110 Someone to use D.B. in this situation however later on I will go through and normalize everything to 128 00:09:32,410 --> 00:09:34,060 underscore D.B.. 129 00:09:34,150 --> 00:09:35,320 All right. 130 00:09:35,320 --> 00:09:43,540 So private read only car into entities the B and then inside of my constructor on an I underneath initialized 131 00:09:43,570 --> 00:09:50,760 component I'm going to see on the score d d equal to a new instance of car into entities. 132 00:09:50,800 --> 00:09:52,810 So that's the initialization right. 133 00:09:53,170 --> 00:09:59,250 So in our program runs are when this form is launched it knows all of the DV. 134 00:09:59,240 --> 00:10:03,010 Then initialize is its components and the DB. 135 00:10:03,220 --> 00:10:10,010 And then throughout the rest of the form any time we need to talk to our database we have or underscore 136 00:10:10,020 --> 00:10:11,740 D.B. object. 137 00:10:11,740 --> 00:10:18,160 So the first thing I want to do is run the query to get the car words to say var cars and I use cars 138 00:10:18,160 --> 00:10:25,630 and vehicles interchangeably so whichever one you want to use that's fine but var cars is equal to database 139 00:10:25,870 --> 00:10:29,730 connection Dot and I don't want the car into a record. 140 00:10:29,730 --> 00:10:34,750 So I kind of scroll until I see the table that looks like what I want which is types of cars. 141 00:10:34,750 --> 00:10:38,220 And then I can see a dot to list. 142 00:10:38,290 --> 00:10:47,140 So I want the list or at least of the types of cars in my database and then I'm storing all of those 143 00:10:47,230 --> 00:10:50,370 inside of a variable called cars. 144 00:10:50,390 --> 00:10:50,740 All right. 145 00:10:51,160 --> 00:10:58,210 And then the next step would be to let the data grid know that each should be displaying whatever is 146 00:10:58,210 --> 00:11:00,620 going back instead of the list of cars. 147 00:11:00,670 --> 00:11:03,540 So I can see GV. 148 00:11:03,540 --> 00:11:04,500 All right. 149 00:11:04,570 --> 00:11:13,840 So because I renamed it I know it's a grid view so I call it GV vehicle list dot data source is equal 150 00:11:13,840 --> 00:11:15,790 to cars. 151 00:11:15,840 --> 00:11:16,260 Right. 152 00:11:16,720 --> 00:11:25,180 So the list of cars going back from the database will serve as the data source for my data grid. 153 00:11:25,180 --> 00:11:26,690 So let us see how that looks. 154 00:11:26,720 --> 00:11:32,740 I click start and then when the window comes up I'm clicking and nothing is happening otherwise nothing 155 00:11:32,740 --> 00:11:37,750 happening and we see that we still have a street menu item but nothing is happening and that's because 156 00:11:38,020 --> 00:11:44,890 I did not finish up my click event so I finished wiring up the form or at least for now I've wired the 157 00:11:44,890 --> 00:11:52,750 form so I'm going to go back over to my main window design or to the code file or rather and then here 158 00:11:52,750 --> 00:12:00,000 is that click events I have to go to design because I missed a menu item so I need to delete this one. 159 00:12:00,120 --> 00:12:01,160 All right good. 160 00:12:01,810 --> 00:12:07,840 So now that we've cleaned up the interface back in our code file what we need to do is let the button 161 00:12:08,050 --> 00:12:09,460 launch the new form. 162 00:12:09,460 --> 00:12:20,000 So I'm just going to say var and this one is going to be vehicle listing is equal to new and I call 163 00:12:20,000 --> 00:12:22,790 it vehicle mileage vehicle listing. 164 00:12:22,820 --> 00:12:24,350 All right. 165 00:12:24,350 --> 00:12:27,920 And then I have to say that it's MDI appearance. 166 00:12:27,950 --> 00:12:35,410 Is this so vehicle listing that Amber's a parent is equal to this which is mean window. 167 00:12:35,420 --> 00:12:41,520 And then finally after all of that out of the way I want to show. 168 00:12:42,140 --> 00:12:44,100 All right so let's try. 169 00:12:44,130 --> 00:12:47,770 That's getting someone to launch our application. 170 00:12:47,780 --> 00:12:54,410 And then when I click Vintage Vehicle listing now we're seeing our listing and look at this no. 171 00:12:54,410 --> 00:13:00,450 So we're seeing the grid view and I mean it looks somewhat anemic or we see the big green box. 172 00:13:00,470 --> 00:13:04,070 We see the grid filling out it does much of the box as possible. 173 00:13:04,100 --> 00:13:11,720 We see that we're getting about the I.D. and the name and this seemingly random column from the database 174 00:13:11,720 --> 00:13:13,650 called car into records. 175 00:13:13,700 --> 00:13:19,760 But the fact is that we are seeing the car rental records in that grid views and all we can go back 176 00:13:19,760 --> 00:13:22,460 to this window and maybe clean it up a bit. 177 00:13:22,460 --> 00:13:24,690 Someone's a get out of this. 178 00:13:24,900 --> 00:13:32,150 Someone to modify the width of this grid view because I really don't need to needed to fill that much 179 00:13:32,150 --> 00:13:33,680 space with two columns. 180 00:13:33,740 --> 00:13:37,910 So I'm seeing Aidid name and cover car rental records. 181 00:13:37,960 --> 00:13:41,940 How do I explain what that seemingly random column is. 182 00:13:41,990 --> 00:13:50,060 But I want to add the button so I did take it's the ability to edit to add and remove the cars from 183 00:13:50,260 --> 00:13:56,900 the menu listing in the main window so what I'm going to do is put buttons inside of this window that 184 00:13:56,900 --> 00:14:02,900 will be responsible for helping us do those actions right. 185 00:14:02,930 --> 00:14:11,870 So I went to have four buttons or three buttons so I made one button that I'm just copying and pasting 186 00:14:11,970 --> 00:14:13,470 and I have a spare one. 187 00:14:13,510 --> 00:14:14,120 All right. 188 00:14:14,120 --> 00:14:22,370 And then for my buttons for the properties one I want to take to see what I wanted to do so but no one 189 00:14:22,400 --> 00:14:28,550 let's say we want to meet this add new car right. 190 00:14:28,690 --> 00:14:30,260 The button three. 191 00:14:30,430 --> 00:14:36,130 I want this and other spin properties so that I don't have to keep on going in and going Oh it's so 192 00:14:36,130 --> 00:14:37,080 button three. 193 00:14:37,210 --> 00:14:39,240 I want this one to be edited. 194 00:14:39,310 --> 00:14:46,220 Car and then this one would be delete car. 195 00:14:47,290 --> 00:14:53,740 And then another important step to having my buttons is that I don't want them to be beaten and button 196 00:14:53,740 --> 00:14:59,680 one button to button three I want them to have sensible names that I can reference them in the code 197 00:14:59,680 --> 00:15:00,050 behind. 198 00:15:00,070 --> 00:15:00,460 Right. 199 00:15:00,690 --> 00:15:04,130 So but no one wants renamed to be GM. 200 00:15:04,150 --> 00:15:07,660 That's my prefix for a button car. 201 00:15:07,810 --> 00:15:08,780 All right. 202 00:15:08,780 --> 00:15:14,140 Edit car is going to be Beatty and edit car. 203 00:15:14,140 --> 00:15:14,860 All right. 204 00:15:14,890 --> 00:15:20,170 And then the final one would be Beatty and the lead car. 205 00:15:20,170 --> 00:15:21,090 All right. 206 00:15:21,190 --> 00:15:25,420 So then I can go ahead and create click events for them from no if I want. 207 00:15:25,420 --> 00:15:30,000 So I'm going to double click the ad car and notice because I gave it a sensible name. 208 00:15:30,070 --> 00:15:31,630 The click event is very clear. 209 00:15:31,630 --> 00:15:34,280 Beatty and ad car on the score click. 210 00:15:34,300 --> 00:15:35,200 Correct. 211 00:15:35,200 --> 00:15:41,280 So I can just go ahead and create all those events accordingly. 212 00:15:41,290 --> 00:15:46,090 So just go back and double click each until I have those click events and then this is why I don't like 213 00:15:46,090 --> 00:15:50,620 pinning properties because in when writing code it's not useful. 214 00:15:50,640 --> 00:15:50,980 Right. 215 00:15:52,090 --> 00:15:56,440 So then I have three button click events with three buttons on my form. 216 00:15:56,440 --> 00:15:58,690 So that's just some cosmetic stuff. 217 00:15:58,690 --> 00:16:02,010 That's a start again and see what that looks like. 218 00:16:02,010 --> 00:16:02,410 All right. 219 00:16:02,410 --> 00:16:07,690 So now we see that a grid is a bit smaller and we have the data being displayed. 220 00:16:07,690 --> 00:16:08,410 Sure. 221 00:16:08,470 --> 00:16:14,260 But then to the right we see our buttons and well they're all dead buttons because they have click events 222 00:16:14,290 --> 00:16:17,700 but the click events aren't doing anything just yet. 223 00:16:17,710 --> 00:16:20,200 So no I want to clean up the grid a bit. 224 00:16:20,200 --> 00:16:26,650 I don't want the I.D. and name columns to be displaying in come on letters like that. 225 00:16:26,680 --> 00:16:35,350 So what I'm going to do is inside of my form load phone shun when I set the data source I noticed that 226 00:16:35,350 --> 00:16:40,840 when the data grid is generating the columns relative to the data it is being fed. 227 00:16:40,870 --> 00:16:49,540 So I'm feeding it the list of cars and the list of cars each object has I.T. it has name and some list 228 00:16:49,540 --> 00:16:51,330 of car rental records. 229 00:16:51,330 --> 00:16:51,830 Right. 230 00:16:51,880 --> 00:16:54,160 Which I'll soon explain exactly what that is. 231 00:16:54,160 --> 00:16:57,640 Well at least later on we'll see exactly what that is. 232 00:16:57,640 --> 00:17:06,860 So what I'm going to do for my data grid is I'm going to say GV vehicle list dot and then I want to 233 00:17:06,950 --> 00:17:12,960 specify that I want the first column which I know is going to be I.T. second C columns. 234 00:17:13,130 --> 00:17:15,880 And if you have ever worked with Aries our collection. 235 00:17:15,890 --> 00:17:20,570 So we are working with that list and that's our collection type of a work with an array you know that 236 00:17:20,570 --> 00:17:23,560 the square brackets represent. 237 00:17:23,810 --> 00:17:28,640 You can specify exactly which subscript of the Ari you want. 238 00:17:28,640 --> 00:17:28,960 Right. 239 00:17:29,240 --> 00:17:30,370 So if you haven't. 240 00:17:30,380 --> 00:17:31,040 That's fine. 241 00:17:31,040 --> 00:17:31,910 So let me explain. 242 00:17:31,940 --> 00:17:33,890 So the columns here. 243 00:17:34,160 --> 00:17:38,650 This is a grid view control and then I'm saying I want the columns. 244 00:17:38,660 --> 00:17:42,770 And if it's columns that means it's off collection there's more than one columns. 245 00:17:42,770 --> 00:17:49,820 I want the first column which I know as a programmer is going to be Ida anyway so I can see square brackets 246 00:17:49,820 --> 00:17:54,650 zero because in computers you start counting from zero not one. 247 00:17:54,650 --> 00:17:54,920 Right. 248 00:17:54,950 --> 00:17:57,500 So the first subscript of 3 0. 249 00:17:57,950 --> 00:18:06,440 So the first script is 0 and then I want the property of this which is the header text to be equal to 250 00:18:06,440 --> 00:18:09,350 the text I.D. in all caps right. 251 00:18:09,380 --> 00:18:17,210 So I'm seeing that after I get this stuff cars and then I get and then I said the data source at this 252 00:18:17,210 --> 00:18:19,990 point all of the columns would have been generated. 253 00:18:20,050 --> 00:18:26,750 I am seeing that the first column that was generated I want the heretics to be I.D. And then I want 254 00:18:26,780 --> 00:18:32,110 the second column so I'm just going to duplicate that line and Jesus a subscript from 0 to 1. 255 00:18:32,360 --> 00:18:37,460 And I want this one to be name in all caps. 256 00:18:37,580 --> 00:18:37,820 All right. 257 00:18:37,820 --> 00:18:38,720 So let's see. 258 00:18:38,750 --> 00:18:39,390 Hold that look. 259 00:18:39,390 --> 00:18:46,810 So if I click Start then I'm going to see that I'm getting Idi name and I'm still seeing Kyra into records. 260 00:18:46,820 --> 00:18:51,140 But at least the column headers are changing accordingly. 261 00:18:51,140 --> 00:18:53,300 So that's encouraging at least. 262 00:18:53,300 --> 00:18:53,740 All right. 263 00:18:53,960 --> 00:19:01,850 So the next thing I want to do is to eliminate the fact that I'm getting but that seemingly random car 264 00:19:01,850 --> 00:19:03,100 into records column. 265 00:19:03,110 --> 00:19:08,000 But before I do that let me just explain a bit to what that represents. 266 00:19:08,000 --> 00:19:12,540 So I opened up my day it's a model which is the idea makes file and I'm seeing this yard. 267 00:19:13,040 --> 00:19:19,700 If we look in the table types of car or types of cars we will see that we have the idea we have the 268 00:19:19,700 --> 00:19:25,760 name and then below we have this navigation property called car and title records. 269 00:19:25,760 --> 00:19:26,060 Right. 270 00:19:26,360 --> 00:19:34,610 So just humor me for a bit and let me take you on this journey if you will have our intel system and 271 00:19:34,610 --> 00:19:41,180 then you will have a car that is rented multiple times then that means that this car is associated with 272 00:19:41,180 --> 00:19:42,550 multiple records. 273 00:19:42,560 --> 00:19:42,890 Right. 274 00:19:42,890 --> 00:19:50,270 So if I wanted to know how many times my I believe of a car called Lada or Honda how many times my Honda 275 00:19:50,270 --> 00:19:56,610 was rented then I would have literally at least off the times this car was rented. 276 00:19:56,670 --> 00:19:56,920 Right. 277 00:19:57,170 --> 00:20:01,040 So that is exactly what this navigation property represents. 278 00:20:01,040 --> 00:20:06,770 It says that for any car that you're going to look at I can show you the list off or into our records 279 00:20:06,770 --> 00:20:10,690 that it is associated with because they are related. 280 00:20:10,730 --> 00:20:11,400 All right. 281 00:20:11,420 --> 00:20:18,140 And then in the same way the car into record knows the exact type of car that was rented in this record. 282 00:20:18,140 --> 00:20:26,570 So this is whole link and an entity framework actually global it's helping you to form good relationships 283 00:20:26,570 --> 00:20:34,220 between your tables and actually query data across multiple tables with much ease but without getting 284 00:20:34,220 --> 00:20:38,660 too much into you know complicating exactly how they're used right. 285 00:20:38,660 --> 00:20:43,700 No I don't need the reference to the car rental records just yet. 286 00:20:43,730 --> 00:20:50,720 So back in my code file I'm going to tweak this query a bit to select exactly what I want. 287 00:20:50,720 --> 00:20:53,200 So this is doing a select style. 288 00:20:53,230 --> 00:20:59,630 And we did a select star in our adder into our record once again for our combo box where I said that 289 00:20:59,630 --> 00:21:04,490 doing it this way is just like seeing select star in this case with OnStar. 290 00:21:04,500 --> 00:21:10,040 We literally just want I.D. and name because when we're doing it this way we're getting but the random 291 00:21:10,280 --> 00:21:14,350 seemingly random column of car into the records. 292 00:21:14,360 --> 00:21:15,010 Right. 293 00:21:15,050 --> 00:21:21,530 So I'm going to go back and I'm going to show you how we can treat this someone to come in this place 294 00:21:22,160 --> 00:21:29,290 and I'm going to say that this is the way you do select star from types of cars right. 295 00:21:29,300 --> 00:21:30,500 Just so we're clear. 296 00:21:30,650 --> 00:21:34,810 But then I'm going to rewrite this story and I'm going to walk you through exactly what we're doing. 297 00:21:35,270 --> 00:21:37,790 So I'm going to save our cars. 298 00:21:37,790 --> 00:21:45,890 Once again is equal to the connection to the database not the table that I want. 299 00:21:46,100 --> 00:21:50,750 Well then I'm not willing to say at least this time I'm going to say not silly. 300 00:21:51,650 --> 00:21:52,640 All right. 301 00:21:52,640 --> 00:21:58,040 And then when I do that I'm going to have to work a bit of I want to call it magic. 302 00:21:58,060 --> 00:22:00,530 But as I said I'm here to guide you through. 303 00:22:00,590 --> 00:22:05,340 So I want to select just the two columns that I want. 304 00:22:05,430 --> 00:22:10,190 I'm sure if you do if you're used this school then you would think that you'd say Oh I. 305 00:22:10,220 --> 00:22:10,870 Come on in. 306 00:22:10,880 --> 00:22:15,200 Well it's unfortunately not that simply in C sharp. 307 00:22:15,350 --> 00:22:22,910 We're going to have to do what we call a lot of lambda expression where we create an object. 308 00:22:22,910 --> 00:22:23,660 All right. 309 00:22:23,660 --> 00:22:24,920 So this is lambda. 310 00:22:24,920 --> 00:22:25,510 So this. 311 00:22:25,550 --> 00:22:26,780 That's just it's right. 312 00:22:26,790 --> 00:22:28,820 There's nothing more to explain. 313 00:22:28,820 --> 00:22:32,200 The only thing I can explain here is that this doesn't have to be a Q. 314 00:22:32,210 --> 00:22:33,350 This could be a W. 315 00:22:33,440 --> 00:22:35,300 This could be a word. 316 00:22:35,300 --> 00:22:43,880 I mean you can use any expression you want but the Q or whatever expression you you use here is going 317 00:22:43,880 --> 00:22:48,200 to represent every object that is inside of the collection. 318 00:22:48,200 --> 00:22:48,910 Right. 319 00:22:48,950 --> 00:22:51,850 So this is just how you start a lambda expression. 320 00:22:51,860 --> 00:22:58,640 You have an expression what you want is a letter or a word or whatever and then you have equal and then 321 00:22:58,790 --> 00:23:02,020 the greater than saying or I just called it the arrow. 322 00:23:02,150 --> 00:23:02,480 Right. 323 00:23:02,510 --> 00:23:12,080 So you have the expression then the arrow and then this allows you to see what columns you want from 324 00:23:12,080 --> 00:23:12,680 the table. 325 00:23:12,680 --> 00:23:19,850 So I am saying select then I initialize alumni expression and then using the lambda expression I can 326 00:23:19,850 --> 00:23:23,830 see CU dot I.D.. 327 00:23:24,070 --> 00:23:24,870 Right. 328 00:23:24,920 --> 00:23:28,640 But then I don't want just idea I want a new object. 329 00:23:28,640 --> 00:23:33,620 So what I'm want to see is new and then I'm open up. 330 00:23:33,830 --> 00:23:40,010 I open up my curly braces and then inside of this I'm going to specify that I want. 331 00:23:40,210 --> 00:23:54,160 And Heidi being equal to Q Dot I.D. then I can use my comma and say I want a new a new property called 332 00:23:54,160 --> 00:23:58,720 name and it should have the value Q Dot name. 333 00:23:58,720 --> 00:23:58,980 All right. 334 00:23:59,260 --> 00:24:02,690 So if you're you still askew and aliasing. 335 00:24:02,700 --> 00:24:09,600 All right we're in escrow you would've said something like SELECT this and you give it an alias so that 336 00:24:09,670 --> 00:24:17,370 selected the column I would say select I.D. as another name on select to name as something else or whatever. 337 00:24:17,410 --> 00:24:22,070 This is how you go about doing aliasing inside of the link. 338 00:24:22,090 --> 00:24:22,780 Right. 339 00:24:22,780 --> 00:24:29,350 So once again let me just walk you through what we're doing or saying I want to connect to the database. 340 00:24:29,380 --> 00:24:32,980 Give me the table and then I want to select. 341 00:24:33,790 --> 00:24:39,840 And then we do a lambda expression and then after the lambda expression we are selecting a new object. 342 00:24:39,850 --> 00:24:42,680 So we're literally just building an object on the fly. 343 00:24:42,680 --> 00:24:48,190 This this is just a new object that we're creating for our own purpose and what I want in my object 344 00:24:48,490 --> 00:24:55,240 is a property called I.D. which is going to get the value that's coming from the database with an I.D. 345 00:24:55,620 --> 00:25:01,870 come on another property called name and it is going to get the value coming from the database with 346 00:25:01,870 --> 00:25:02,660 the word name. 347 00:25:02,770 --> 00:25:04,960 And once again these are aliases. 348 00:25:04,960 --> 00:25:05,260 Right. 349 00:25:05,260 --> 00:25:11,860 So I could have used anything here I didn't have to use idea name again I could have used car I.D.. 350 00:25:12,460 --> 00:25:13,050 Right. 351 00:25:13,090 --> 00:25:16,130 And I could have used car name. 352 00:25:16,210 --> 00:25:17,530 It doesn't really matter. 353 00:25:17,560 --> 00:25:20,880 So it's up to me to know what I am naming these. 354 00:25:21,010 --> 00:25:22,900 Once again these are aliases. 355 00:25:22,900 --> 00:25:30,040 If you are used to school and then for as many properties as they're coming back on I want and I want 356 00:25:30,040 --> 00:25:37,540 to create an alias I could just say Como and do the same alias e was lambda expression dot whichever 357 00:25:37,540 --> 00:25:38,710 column I want. 358 00:25:39,080 --> 00:25:42,080 All right lambda variable or other. 359 00:25:42,090 --> 00:25:46,620 And then after doing all of that I notice all of that's happened instead of the curly braces. 360 00:25:46,720 --> 00:25:52,480 Then I would end with a semicolon but then I would probably want to do a list also. 361 00:25:52,480 --> 00:25:54,670 So I like lists so. 362 00:25:54,700 --> 00:26:00,920 And just me it makes it much easier to just when you do a link query just make everything I list afterwards. 363 00:26:00,940 --> 00:26:05,410 If you're selecting expecting a collection of results. 364 00:26:05,410 --> 00:26:05,700 Right. 365 00:26:06,070 --> 00:26:10,990 And then some people would actually break this into multiple lines so they would actually do something 366 00:26:10,990 --> 00:26:20,270 like the query here and then they a dot select in another line and then so then they would do that. 367 00:26:20,300 --> 00:26:23,550 Oh it's a bit more I won't do that one though. 368 00:26:23,650 --> 00:26:28,300 So that is how you would go about building open aliasing system. 369 00:26:28,300 --> 00:26:39,020 So this situation will be more like select and then I would say something like I.D. as car I.D.. 370 00:26:39,250 --> 00:26:48,550 Kamal name as car name from types of cars. 371 00:26:48,590 --> 00:26:49,870 Right. 372 00:26:49,960 --> 00:26:56,040 So I'm gonna show you that link is variable for that and it does create some wonderful obstruction from 373 00:26:56,040 --> 00:27:00,000 the typical school while maintaining C sharp code. 374 00:27:00,000 --> 00:27:02,490 It does take practice it does day getting used to. 375 00:27:02,730 --> 00:27:09,150 So if you will have to kind of do it to be able to reap the benefits of what it allows you to do. 376 00:27:09,150 --> 00:27:09,480 Right. 377 00:27:09,960 --> 00:27:16,850 So if I do start again and then we look at our grid we see that we're getting bug eyed. 378 00:27:16,860 --> 00:27:22,950 You are getting by name and we're only getting about those two we're not getting that third column again 379 00:27:22,950 --> 00:27:30,240 and that's once again because I specified what I wanted to select on even though I changed the names 380 00:27:30,270 --> 00:27:37,920 I still told the grid view that the IDA ideas should be the column name for the first one I name the 381 00:27:37,920 --> 00:27:43,860 column name for the second one so I'm just going to put our breakpoint at the point where we're sitting 382 00:27:43,860 --> 00:27:48,990 the data source and I want to close the window and I'm going to load it again and then I'm going to 383 00:27:48,990 --> 00:27:55,170 look instead of my car's variable where you see it's coming back with five and if you look at the object 384 00:27:55,230 --> 00:27:57,810 listing you're seeing car idea and car names. 385 00:27:57,810 --> 00:28:06,150 So we created custom objects that we wanted to create at least and then that that list of custom objects 386 00:28:06,420 --> 00:28:14,040 is being used as a data source for our grid and then we set the column names and then our grid is displayed. 387 00:28:14,070 --> 00:28:18,800 So I'm removing the breakpoint clicking continue and that is the okay. 388 00:28:18,840 --> 00:28:25,470 So in the next video we'll start looking at how we wire up these buttons for adding to the database 389 00:28:25,560 --> 00:28:31,010 editing car record and removing a car record.