Well Done Tim, I've been a long time developer in VB and the transition to C# and WPF has been made so much easier with your tutorials, Please keep it up Thanks from down under
Hey Tim, That was quick. Thanks for obliging my request for a "DataGrid" session. Good job with the 'CellEditingTemplate'/'DatePicker', learnt something new. Looking forward to other contents on WPF... Keep up the good work. 👍
I'm gonna show this video to some of my coworkers for sure. I'm trying to convince them to move to WPF from winforms as our solution grows and grows and grows and their biggest worry is that somehow it will be be harder to work with grids. I think I'll just show them the first 5 minutes of the vid so I don't scare them off with the templating stuff :) bind to an item source. Done!
LMFAO... At 3:20.... LMFAO... This is the fourth or fifth video of the WPF collection that I have been watching... I can't stop laughing !!!! Your videos are awesome thank you so much!!
@@IAmTimCorey Basically I have a File converter for a tool I'm writing. It reads in data from a legacy system, which I convert and then upload to SQL Server tables, depending on the data model. I have a static method which I pass a file, this says Ahh! It's this Table you are dealing with (do some magic) pass back the List and my WPF DataGrid displays a sample of that converted data. So, what I did is use dynamic in the BindableCollection. Works a treat! I don't normally think of dynamics as they have a price :)
Hey Tim, REALLY terrific content!! Thank you for everything. Think you could do a more advanced video which illustrates dealing with changes in the DataGrid in MVVM? For example, only processing objects or properties which have changed. Again, thanks for all of the great tutorials and knowledge sharing!!!
Hi Tim, I'm glad you're still replying to comments until this day. I do have a problem on my project. Lets say I have a datagrid with rows of numbers and I have a property to add all of those numbers. Now I want to run the addition property every time I edit a row on the UI but it doesn't. Using a button obviously works but automatically, no. I used NotifyOfPropertyChanged but it seems to not trigger it when editing on the datagrid.
Hi Tim, thanks for sharing this. I use DataGrids a lot, if fact it is my major way to show tables. I use HeaderTemplates, that allow to set filters on the data, I use RowDetails, to expand a row a bit. Up till now, I did not integrate editing like you do, it's an idea to consider. At the moment I try to master DataGrids with with a variable numer of columns, which are generated dynamically. My first attempt is now working, but it only supports strings. In my second attempt I want to use objects and create a form of templating for the DataGridCells, to allow for a nicer markup. I just discovered you can freeze the first column, which is very useful. I always will use scrollbars, but this requires to fix height and width of the DataGrid. So there really is a lot you can do with this.
I saw your video "How to connect C# to SQL (the easy way) " (which is great by the way) and now this and I have a question. What can I do if I want to update the database when I write a new row into the gridview??? Basically I have a problem extracting the data from datagrid and save it as a list. Please do a video because for the last 8 hours I found nothing on TH-cam.
Great video Tim! Really usefuI. I am planning an app in which a user selects a person from the datagrid view and then opens a usercontrol to edit the person''s details in a form view. The user would then save the data (to database) and return to the datagrid. Would it be possible to show us perhaps in a future video the proper way to do that? Looking forward to see more WPF and any other topics you plan for us. Thanks.
I could probably do that. For now, it should just be an event on the click event for the row where you call a method in your controller and edit that row in the new UserControl.
Hello Tim, very quick question. What is the difference between Binding ="{Binding FullName}" and Binding="{Binding Path=FullName}" the reason why I am asking this, is because looking back at the other tutorials you used mostly the version without path and because both seem to work.
Came here to see what I did wrong with adding my list of custom objects to a DataGrid source. You skipped over that part. But while writing a three-paragraph ranty text about it, checking my code and going back in your video for specifics, I figured my issue. Though you're not showing it in the video, I realized I had to both set each property I wanted to show to "public" rather than "protected" AND create the getters and setters. I had tried before by just switching them to public, but that did not work. I'm a newb when it comes to C#, so I don't yet know when it is important to specify { get; set; } yet. Most other languages I've worked with will assume these two methods on all accessible properties. Since, you know, it's rather silly to have a public property you cannot access from the outside. Anyway, great video as always, the issue was entirely on my end, and this has just been another example of how you sometimes find the answer to your problem by trying to explain it to someone else. Which I guess is why teaching others is a great way to learn yourself.
WPF Binding kicks my A over and over and over. I still don't understand it. Its so inconsistent. Now the name of the table is used as a binding specifier? I'm so beaten down from it.
Can you explain better how you bind the BindableCollection to the datagrid? I just dont get how it bind it just with the name. Im very noob at WPF and i really dont understand anything.
When you bind it without specifying any of the properties, .NET goes through and maps out what columns the properties should each be automatically. That is good for general models but for more specific ones you should map it out yourself like I did in the video.
Hi Tim, you used a "BindableCollection" as your binding source, as I understand... Would a List work as well, in case I want to bind to collection as binding source? And if it doesn´t, why not? What do I have to keep in mind, trying to bind an ItemsView to a collection? I have a Problem trying to bind a DataGridTextColumn in code-behind to a List . Can you please make a video on doing the same in code-behind, what you did in this video in XAML? I think, understanding how binding works is best using code behind. Thank you for your efforts!
Thank you for the excellent example Tim. Can you wire up for instance a click or double click event on the cell content of the datagrid and maybe have it filter the results of a particular column that you clicked in? For instance click in the Birthday column on a value with a certain year and filter the results with birthday's of that year.
Yep, you can check out the event list by looking in the properties window and viewing possible events when you have selected the grid or row definition. Then you can bind it to a method in your ViewModel.
Tim does not x:Name define the name of the UI control? So if we use the same name for a property and a UI component, CM renders it? ( I hope I used the right technical words ) And if the UI control like TextBlock does not have x:Name option, we use Binding right?
Your lessons are wonderful ... Thank you too much Sir. My question … are you think to do lectures in analyzing “Big data” using Excel, depending on “data mining Excel AddIns tools”, and also by using the some intelligence techniques like “Genetic Algorithm Excel AddIns tools” thank you too much and I wish you always success
I'll be doing some things with Excel (exporting to and importing from Excel in C#) but I doubt I'll get into Big Data or data mining. That is kind of outside the scope of this channel.
Thank too much Dear Doctor I hope that this will be within your interests in the future at least to deal with the data mining tool (AddINS) and how to add it to excel and deal with it and is it free and possible to be added at any time ...
Hi Tim, I was playing around with Datagrid in this demo. One feature that came to my mind was how to implement Find and replace functionality as we see in Microsoft Excel. This was a practice and to do problem solving. I bind datagrid item source to a datatable in my viewmodel. To implement Find and replace functionality, i found one approach but couldn't achieve it. It is like this: I compare a textbox value entered by user with one datatable column's value, and change those value with a new textbox value(say RepalcetextBox), but after I bound data to datagrid, I couldn't compare data column value with textbox value as now I have to deal with DataGrid data and not DataTable values. Can you please tell me if my approach is correct or where I'm going wrong. Do you see think of any other approach I can achieve?
I would work directly with the models, not with the UI elements. So when you do a Find and Replace, don't search the DataGrid, search the List that supports the DataGrid. Then replace in them.
You are awesome many thanks for the magnificent tutorial but what is the BindableCollection is?? and how to bind data in excel to datagrid (number of columns & names are not know)? thanks again
You would need to figure that out at some point. When you get data from Excel, you would need to put it into columns and rows. To use it effectively in C#, you would then need to assign that data to a strongly-typed object that has defined properties. Otherwise you can't do easy binding like this. You will need to do a more manual binding process.
@@IAmTimCorey first, many thanks for your fast replay i do put the excel data in datatable, i hope this not breaking the MVVM pattern but i can't have full control on it,i miss the properties to bind it as i wish also, i found it too hard to create checkbox column and bind it to row selection , so i can only processing the selected data i hope you can make more videos on this complicated control i'm in this for more than three weeks, but progress is too slow thanks
Great video. One question: while I see how the edits modify the instantiated model (data in memory), how would you trigger committing the changes back to the database?
Great Video Tim!! i was wondering if you have a video that explains all the different events on DataGrid such as BeginningEdit, PreviewLostKeyboardFocus, InitializingNewItem, CellEditEnding ... etc ?
Hi, Thanks for the videos but I think the wpf series is highly missing a tutorial for events (or event aggregation) on caliburn micro. Can you please make a tutorial on that?
You can see events and event aggregation in the TimCo Retail Manager series, where we have an API middle layer and a WPF front-end. Specifically, when the user logs in, it fires an event that opens up a new form.
@@IAmTimCorey Awesome! I'd like to see how to exactly save edits from the data grid and working with multiple views/pages. I'm still new to WPF and MVVM so excuse my ignorance.
What would you recommend as a replacement for the Windows Forms PropertyGrid? I find it strange how there does not seem to be one in WPF when Microsoft very clearly has one built for their own use in several of their applications that utilise WPF, or so it would seem.
Great sets of videos I have learn a ton. I did have a question on the datagrid combox. I noticed that the down arrow is missing unless you click on the cell. Is it possible to have the arrow showing all the time? if so how?
Very clearly explained, thank you. I would like user have provision to sort and filter data grid columns like Excel, It will be great if you could share a link where it has implemented or guided how it has to be done. Thank you so much.
Hi Tim, I can populate the WPF Datagrid - is there more information about saving the row changes back to an object model that can be saved back to SQL Database Table?
This is very good! Thanks for putting effort into making this video. I’m fairly new to WPF and I’ve learnt a lot from this video. I have a question if you don’t mind... how would you do it if you’d have to highlight cells that have a certain value? Say, for example, a list of users having an “Active” column that can be “Yes”/“No” (or true/false) and you want to set the background colour to light green for all those having “Yes” in that column. Many thanks.
Hi Tim, Thanks for the amazing Tutorial. I am currently building a Datagrid and it has a column that is supposed to provide a drop down with a editable textbox in case if the desried value is not in the drop down. my datagrid is bound to a datatable. It takes in the value i enter correctly, but while displaying it splits the value into single characters and displays them as sepearet items. Would be glad to hear from you.
Hey Tim! Do you have any materials on how to bind this ComboBox to List that is outside of Person model? Like if the Addresses are just a list(taken and updated from database) and you can select for every person a address from there? Makes more sense, if i have one list of address and Person model holds only the Id to that address(as its done with the WinForms combobox). I have searched a bit but haven't found as nice tutorial as you do on these topics(i even started the C# mastercourse on your website thanks to these youtube videos). Usually when the code starts to scare me, then i know that there is a simpler way to do it...
Hi Tim, if I change values, or add a new line, does that automatically change the values in the object? For example, if I have bound an Entity Framework Class to the DataGrid and I make changes in the grid, is it enough, just to call 'SaveChanges()' Method of the EF Framework?
Hey Tim...using caliburn micro (or anything else) is there a way to get the datagrid to refresh without code-behind? I have a form that creates the new item and a button in the datagrid that deletes it; but it's not refreshing. My Datagrid is is named the same thing as my bindablecollection.
@@IAmTimCorey Not sure I follow just yet. So I have a ViewModel (SettingsViewModel) that loads up a Model called LinkPatterns. this is getting data the same your your example does: DataAccess class that loads data into the LinkPattern model from the app.config file. I'm calling DataAccess from the SettingsViewModel contructor so it loads at startup. Datagrid is populated just fine there. Based on your response, I think the problem is when I add a new link pattern, I'm adding by a method that writes xml to the app.config file directly. Soooo, basically nothing is going to automatically load this datagrid with the new entry until my VM opens again. I'm not very advanced, but I think I can find my way around adding my new pattern to the collection, but won't collection have all of my previous records there? If so, I don't know how to only write the new one.
Hello, Sorting on column-header click for the data template column doesn't work directly in this example, we need to set the SortMemberPath attribute to enable sorting. Just for other beginners like me who face the same issue.
These videos are very helpful, thank you. 1 small question, how can you make calculations with the rows of the datagrid so you can show them in another row? Thank you in advance
Path is being explicit. Sometimes you need to be explicit when other parameters are involved or you have other properties coming in. In general, you don't need it but if you have a problem, adding it can't hurt and can sometimes be the solution.
I'll be doing other things very soon, I just wanted to clear the decks of a few WPF control videos that have been sitting there for a while. I know not everyone wants to use WPF.
Hi Tim, I've been trying to bind my checkbox (inside a datagrid template column) to an event (both property setter and methods, neither worked), i tried everything i could find online for the past couple of hours but nothing seems to work. A regular checkbox works fine with the notifyOfPropertyChange, this checkbox doesn't though. I tried UpdateSourceTrigger=PropertyChanged, RelativeSource AncestorType=DataGrid, and a few other things, with different combinations (all with IsChecked, as checked would give an error), but nothing worked yet
Hi Tim - Your videos have been so much help! I am able to use DataGrid with Caliburn Micro as you have described. What I am really struggling with is how to get the column index for a selected cell. I have tried every combination that I can think of for SelectedUnit = Cell with SelectedCells, SelectionChanged, SelectedCellsChanged, etc. and I have had no success linking my view and my viewmodel at the cell level. Any advice would be greatly appreciated. Thanks!
I believe the solution isn't to try to get the selected row by index but rather through the binding. Bind an object to SelectedItem and you should be set.
@@IAmTimCorey Thanks Tim. I was able to bind a ViewModel property to CurrentCell and get the column index from the associated DataGridCellInfo. When Caliburn uses Name to bind a BindableCollection to a DataGrid, is it possible to assign property values to the DataGrid object programatically from within the ViewModel? I have tried but don't know how to access the DataGrid object from within the VM (I can only access the Collection). Thanks again for everything!
@@IAmTimCorey I tried doing that but the binding doesn't seem to work. Why could that be? I can only presume no item is selected when I push the corresponding button (although the line with the button is colored dark blue so should be selected...)?? Binding using SelectedItem with ItemsControl does work out well so it's not that I cannot work with the "SelectedItem" property and bind it to an Object.
Thank you so much sensei... I needed this..but I still have one more thing left ....it’s the totals row...I want to have a totals row below the last row...
Yep, I agree. I'm just not a designer so I haven't spent a lot of time in Blend. I need to really understand something before I teach it, which means I need to learn it better first.
Hey Tim, you got some awesome and informative videos! I have a quick question, how would you set a button that would delete a row that the user selected from the DataGrid? I'm trying to figure out how to retrieve the data in that selected row to be used to pass a query to my SQLite database. For example, following your video, I would click on a "Full Name" row and click a delete button that would retrieve all the data of that person (Birthday, address, etc..). From there, the rest of the code would use that data to fill in a delete query to a SQLite database. Any advice would be appreciated!
Hi Tim, how would I get all the displayed data out of that datagrid and into a sql server table? Coming from winforms I cannot use row.Cells[0] anymore
Tim just a quick question. If i have a class with Lets say int Id set; get; string Name set; get; and Owner Person set; get; this class called PetModel right? then when i create a method to call all my pets in a DataAccess class i run a query of type PetModel and call my store procedure i get an error that says that i cant parse the column wich i have my Owner because its of type object and my sql table its an int. cant really figure how to solve that.. I would really apreciate if u find some time to answer me. Thanks a Lot.
Hi, I've a problem with this type of binding. After the first binding, if i change in background some value of the collection the UI doesn't refresh the DataGrid values. I can see the new values only by clicking one of the columns header.
@@IAmTimCorey I'm using a bindableCollecion like in your video. I've a InstructionModel class with the property "Executed" to be updated. public BindableCollection Instructions { get; set; } public ShellViewModel() { Instructions= new BindableCollection(); } public void AddInstruction() { Instructions.Add(new InstructionModel { Command = "DEMO", Executed = false }); //It Works!! } public void ExecuteAll() { foreach (InstructionModel item in Instructions) { item.Executed = true; //It doesn't Works!! } NotifyOfPropertyChange(() => Instructions); } ______ In XAML File: ______ The DataGrid shows the result of "AddInstruction" method but not of the "ExecuteAll" method. Debugging I can see that the collection is updated with all the executed parameters to "true".
I have one question about data grids or other controls. If a person wanted to have several buttons and when you click on the button, then it runs a command on the view model, how can that be done with caliburn micro? I've done it before with old fashioned Command. However, I would prefer to be able to invoke a method without the commands. What I would want is when they click on an item, that becomes the parameter that gets sent to the method and even having the Can so if the validation fails, then the button would be disabled.
You can do that. The button can actually be in the model that you have a list of. You could also have the button send the row information on click I believe. Sorry, I don't think I have an example right at hand to show you.
Hi Tim, How to add a button column at the end of the DataGrid and assign a click event to each button in every row. I need to make a DataGrid that gets Factures from the database and I need to put a view button for each facture to view its details. Any help please. Thank you.
There are a few ways of doing it. You could put a method in your model that each button could call. You could also just have each button point to the same method and have it work on the selected row.
@@IAmTimCorey yes but how to add a button. to each row. PS: I can just create a Button btn = new Button() and set is parameters in windows form apps and add it to each row and simply bind, but how to do that in WPF. Can you help with that to??
@IAmTimCorey SORRYYYYYYY for the late reply. Here is the link for the best answer so far stackoverflow.com/questions/55498151/add-a-buttons-to-rows-of-datagrid-and-event-click-to-each-using-caliburn-micro-i/.
Hi, I have a question. I'm making a small Inventory system Project. I'm doing this with the MVVM framework. And in one of my views, I also using a bindableCollection to display all my customers. I also added some Delete and Edit buttons in case the user wants to delete the customer from the datagrid. I have is I would like to use some commands that are also bonded to some ICommand Classes to delete or edit some of those customers. The problem is I can't get those commands because they are not part of the bindable collection. I can only bind to the properties in my collections. What is the best way to do still use those commands? I thought of multiple item sources in order to get those commands but apparently, a Datagrid only allows one item source binding not multiple. Thanks anyway for the amazing content you give.
Tim, I am enjoying your courses! I have added a datagrid to a wpf form. The datagrid is displaying but there is no data in it. I can see the columns and the sorting button, but nothing below that. The data is in a model called ActiveAccounts. I can see the data in the watch window, but it doesn't appear in the datagrid. Data is coming from two different tables in the view, but I tried it with both models and both are the same. Can you suggest why this might be? Ted
Are you auto-generating the columns or manually specifying them? If manual, try auto. If auto, check the list of model you are sending to be sure there is data in it. Also, make sure you trigger the NotifyOfPropertyChanged after loading your list if you are just filling it (try it either way).
@@IAmTimCorey Thanks, Tim. To start, I am Auto generating. The data is there. I am following the TRM course as the basis of the app. The view I am working on corresponds to the SalesView, but I have a combo box and a grid on it. The combo box is populated. I'm going to try a simple view with just a GridBox on it with only one list and see what happens. Ted
Hi Tim, I appreciate your input in making concept of learning C# easier, since I've watched lots' of video tutorials you've posted there. They are mostly very clear and intuitive to get close with the idea. But I have one very big notice regarding MVVM-concept and it's regarding the Caliburn Micro: I would like to implement MVVM without Caliburn micro. Is there any plans to make some observable video with datagrids and comboxes (for example) on this topic. Thank you in advance.
Hint: When you go to my channel page (th-cam.com/channels/-ptWR16ITQyYOglXyQmpzw.html), use the SECOND search option which is under the Subscribe/Unsubscribe button to search my channel. If you look for 'MVVM', for example, you would find these items to address your needs - th-cam.com/video/zvyQNuuTqks/w-d-xo.html (Datagrid) and th-cam.com/video/nKJ_XDoAdtY/w-d-xo.html (Combobox)
Hey Tim I just want to add data (your api exercise data ) and populate in in the DataGrid. Before it was easy cause u could create the columns and select a datasource. I have no idea how to insert simple data in this datagrid... You start off with a complex data source
The data source isn't really important. You can just cut that part out and put in sample code or call an API. Up to you. You just need a List with your data but where it comes from doesn't really matter.
Hi Tim, thank you again. Your tutorials are the best! Is there an easy way to display only the persons that are alive? Even if in the Collection are people which aren’t.
Hi Tim, thanks for your video - super helpful and easy to follow. One question I have that hasn't been mentioned is - is it possible to bind datagrid to not just the properties of a class but other data as well? Say in the Person class, in addition to the the properties you have now, there is also a "public Dictionary Families" that holds the title and names of his/her families as keyValuePairs like . Is it possible to do something like {Binding Path = Families["son"]}? If you have other tutorials that get into binding more please direct me to those. Appreciate your help!
That would be less than ideal. You can bind to a list or even a Dictionary but trying to bind to a specific entry in a Dictionary isn't usually done. Usually, you would surface that into its own property.
Thanks Tim, Great videos! Im am looking for changing the background color of a specific cell, Every cell contains a object Bag. This Bag has a TrialId. I want to give every cell with TrialId "1" the same background color. the same for every trial. So that i have a nice overview of all the cells with the attached trial. Do you know if i can do this in a datagrid, or maybe you have a different solution. Thanks for helping!
Hi Tim, I have data grid on the page....and I have enabled Canfilter property so when I mooise curser over grid column head I can see a tiny text box to filer the perticular column values...so here we ge on my question... When I click on the text box n type any character the data grid will get filtered ..but the text in the textbox which in next to grid header will remains untill unless we manually clear it....so here I want to clear that text when we click on cancel button(it's one of the button on my screen)...can you please help me on this ... Thanks
Just use the ItemSource property and Bind the property with ItemSource with an extension of ".Default". For eg : ItemSource = {Binding MyProperty.Default}
Hi Tim, from this video we can see that the data is static and if you don't mind I want to know what if we want dynamic data in the datagrid I mean the user can input like microsoft excel so we don't need to initialize the data first. thank you and god bless you
Thanks Tim, Very interesting as usual, Then I have a question , I would like to use this Datagrid to a List extract from a SQL db using your previsous video with Dapper. but once the user start changing for example your check box from true to false how to update the database the smarter way ? Thank you very much for your help And If I can suggest a topic for one more video in your todo list is about WPF image display or management or arround this after like zoom or so :) Regards
You can call a method on a number of different events. For one, you could call a method on change of the row. Another idea would be to call a method on change of a specific field. Either way (or others), the method could save the row to the database right away. You could also save all dirty (changed) rows at the end when they submit the form. As for the image in WPF suggestion, I'll keep that in mind. Thanks.
Hi Tim I am trying to create a textbox that is linked to a combo box that has a list which is taken from a database and what I need to happen is as I start typing in the Textbox the list of items in the combo box is reduced based on what I type in the textbox. Is this even possible in WPF?
Thank you for this video . It all works fine except one thing I am trying to achieve and it doesn't work. I want to remove a record in a datagrid using a button that is actually in the grid itself. Though the "SelectedItem" property of Datagrid doesn't seem to work properly. I see other people have a problem with selecting a row in such a grid as well...
@@IAmTimCorey I'm playing with it. It seems the selecting goes fine! The problem lies indeed in the removal. I'm going to do some further experimentaion with it and I'll let you know if it works. Thx for this very fast reply!
@@IAmTimCorey OK it works now if a put a button OUTSIDE the datagrid. Then when I select a row and press the button OUTSIDE the datagrid the row goes away like it should. But when I click the button INSIDE the datagrid and the corresponding row the "DeleteRow" event does not seem to get fired... Wonder why that is.
@@IAmTimCorey Hey. There is one thing I'm really wondering about. What's the purpose of the "Models" folder in MVVM ? Since in this video e.g. you use a folder "Models" uotside Caliburn Micro. Why is that? When do you use the folder "Models" inside the WPFapp itself?
I show you how to create tables and populate them in the TimCo Retail Manager series. I also have a course titled "SQL Developer from Start to Finish" that would be really helpful.
Dear Tim ,Thank you for the amazing Videos, and also sharing knowledge I am a VB windows developer for more than 10 years but know i have to move to WPF with C# and your examples helped me a lot to do that. I am planning to develop a Point Of Sales system with all the functionality of POS regiments like Bar code,print a Precept and Touch screen. would you recommend me to use MVVM with Caliburn Micro or use othe tools for that system. Your recommendation will be highly appropriated, Thanks again for every thing.
Before I get into this video: MVVM and Corbin. I am trying to do everything with just WPF and Dapper (You sold me on Dapper in your 'accessing SQL' video). Will this video confuse me via "GREAT, BUT... If you are trying to do this directly with Dapper and not adding in MVVM/Corbin, then this may not be useful to you..." ??? Thanks Henry.
I think you are referring to when I said MVVM and Caliburn, as in Caliburn Micro. You can see the intro to that in my WPF with MVVM video. This video and a few other WPF videos use the MVVM framework but setting up MVVM on your own is a pain so I use Caliburn Micro as my tool for MVVM since it is easy and powerful.
Hi Sir,I am new to both WPF and MVVM so please pardon if this is a silly question. I am having a datagrid with two groups inside it say Male and Female. It is bound to Collectionviewsource which is an observable collection of persons. I have grouped based on Gender. If I drag a person in Male group to female group, I should be able to see dragged item in female group. Let's say I have a collection of Persons: Vinay, Vijay, Nandini, John, Sukanya etc. These persons are grouped by genders: Male and Female. Within a datagrid, I would like to drag a person from one group to another. I want to achieve this in MVVM way so that when I drag and move person ,property or collection in viewmodel should change. All I need are guidelines to follow. Any help would be appreciated.
0:00 - Intro
0:57 - Prerequisites
1:46 - Demo app overview
2:36 - Creating DataGrid
4:11 - Alternating row background
5:01 - Adding data
7:18 - Columns
10:56 - Dropdown in column
18:19 - Date picker
21:56 - Summary and concluding remarks
Thanks again!
I did not think I can be so capable this fast. I realize there is a lot to learn, and appreciate so much you created this content.
I'm glad you are getting up to speed so quickly.
Well Done Tim, I've been a long time developer in VB and the transition to C# and WPF has been made so much easier with your tutorials, Please keep it up
Thanks from down under
I'm glad I could help.
always a blast being educated by you :)
I'm glad.
Hey Tim, That was quick. Thanks for obliging my request for a "DataGrid" session. Good job with the 'CellEditingTemplate'/'DatePicker', learnt something new. Looking forward to other contents on WPF... Keep up the good work. 👍
Yep. It has been sitting there ready to go for a while. Glad you enjoyed it.
Its amazing! Your examples are useful and you make that easier! Thank you ;)! The best channel with C#.
I appreciate the kind words.
I'm gonna show this video to some of my coworkers for sure. I'm trying to convince them to move to WPF from winforms as our solution grows and grows and grows and their biggest worry is that somehow it will be be harder to work with grids. I think I'll just show them the first 5 minutes of the vid so I don't scare them off with the templating stuff :) bind to an item source. Done!
I am glad it can be helpful.
Really nice! Thanks for sharing all that knowledge.
You are most welcome. Thanks for watching.
To the point. Easy to understand.
Thanks!
LMFAO... At 3:20.... LMFAO... This is the fourth or fifth video of the WPF collection that I have been watching... I can't stop laughing !!!! Your videos are awesome thank you so much!!
I'm glad you enjoyed it and I'm glad I could give you a good laugh.
clear and simple explanation. Thanks!
You're welcome!
Thank you so much Tim, this vid help me a lot! Keep on going!
You are welcome.
Didnt watch it yet but the title says it's going to be good!
I hope you enjoy it.
this really help alot thanks
You are welcome.
Thanks so much !!! It's a great tutorial, I'm speak spanish but understand all perfect!!
Great!
I'm a newbie, I'm learning DataGrid using Dapper. let me download this video. thank you Tim, God bless you ..
Glad it was helpful!
Works a treat. Can you pass a generic List to a BindableCollection, using a single DataGrid dependant on what DataModel is used?
I'm not sure I follow your design.
@@IAmTimCorey Basically I have a File converter for a tool I'm writing. It reads in data from a legacy system, which I convert and then upload to SQL Server tables, depending on the data model. I have a static method which I pass a file, this says Ahh! It's this Table you are dealing with (do some magic) pass back the List and my WPF DataGrid displays a sample of that converted data. So, what I did is use dynamic in the BindableCollection. Works a treat! I don't normally think of dynamics as they have a price :)
Hey Tim, REALLY terrific content!! Thank you for everything. Think you could do a more advanced video which illustrates dealing with changes in the DataGrid in MVVM? For example, only processing objects or properties which have changed. Again, thanks for all of the great tutorials and knowledge sharing!!!
I can add that suggestion to the list.
Hi Tim, I'm glad you're still replying to comments until this day. I do have a problem on my project. Lets say I have a datagrid with rows of numbers and I have a property to add all of those numbers. Now I want to run the addition property every time I edit a row on the UI but it doesn't. Using a button obviously works but automatically, no. I used NotifyOfPropertyChanged but it seems to not trigger it when editing on the datagrid.
If it runs when you click the button, run that same code where you are calling the NotifyOfPropertyChanged.
@@IAmTimCorey It doesn't trigger NotifyOfPropertyChanged which is inside the datagrid property.
@@IAmTimCorey I posted it on stackoverflow. stackoverflow.com/questions/62707786/run-a-method-after-editing-a-cell-on-a-datagrid
Hi Tim, thanks for sharing this. I use DataGrids a lot, if fact it is my major way to show tables. I use HeaderTemplates, that allow to set filters on the data, I use RowDetails, to expand a row a bit. Up till now, I did not integrate editing like you do, it's an idea to consider. At the moment I try to master DataGrids with with a variable numer of columns, which are generated dynamically. My first attempt is now working, but it only supports strings. In my second attempt I want to use objects and create a form of templating for the DataGridCells, to allow for a nicer markup. I just discovered you can freeze the first column, which is very useful. I always will use scrollbars, but this requires to fix height and width of the DataGrid. So there really is a lot you can do with this.
You are welcome.
im having issues with a Ambiguity between the and the BindableCollection People
I saw your video "How to connect C# to SQL (the easy way)
" (which is great by the way) and now this and I have a question. What can I do if I want to update the database when I write a new row into the gridview??? Basically I have a problem extracting the data from datagrid and save it as a list. Please do a video because for the last 8 hours I found nothing on TH-cam.
If you do it the way I outlined in this video, you already have it outside the grid in a List. You can use that data to save it to the database.
Thanks! Very useful
You're welcome!
Great video Tim! Really usefuI. I am planning an app in which a user selects a person from the datagrid view and then opens a usercontrol to edit the person''s details in a form view. The user would then save the data (to database) and return to the datagrid. Would it be possible to show us perhaps in a future video the proper way to do that? Looking forward to see more WPF and any other topics you plan for us. Thanks.
I could probably do that. For now, it should just be an event on the click event for the row where you call a method in your controller and edit that row in the new UserControl.
Please make a video on Dependency property and attached property in wpf. Thank you
I'll add that to the suggestion list. Thanks.
You are big help. Own you beer.
I'm glad I've been helpful.
Hello Tim,
very quick question. What is the difference between
Binding ="{Binding FullName}" and Binding="{Binding Path=FullName}"
the reason why I am asking this, is because looking back at the other tutorials you used mostly the version without path and because both seem to work.
Path is typically implied.
Came here to see what I did wrong with adding my list of custom objects to a DataGrid source.
You skipped over that part.
But while writing a three-paragraph ranty text about it, checking my code and going back in your video for specifics, I figured my issue.
Though you're not showing it in the video, I realized I had to both set each property I wanted to show to "public" rather than "protected" AND create the getters and setters.
I had tried before by just switching them to public, but that did not work. I'm a newb when it comes to C#, so I don't yet know when it is important to specify { get; set; } yet. Most other languages I've worked with will assume these two methods on all accessible properties. Since, you know, it's rather silly to have a public property you cannot access from the outside.
Anyway, great video as always, the issue was entirely on my end, and this has just been another example of how you sometimes find the answer to your problem by trying to explain it to someone else. Which I guess is why teaching others is a great way to learn yourself.
Thanks for sharing. I hope that will help others.
WPF Binding kicks my A over and over and over. I still don't understand it. Its so inconsistent. Now the name of the table is used as a binding specifier? I'm so beaten down from it.
Here binding works this way only because he is using caliburn micro. It doesn't work that way normally
Nice, it’s useful
Thank you!
Was waiting for it eagerly. Thanks much
Just curious which is next control you are going to teach us?
You will have to wait and see (although I always take suggestions).
Can you explain better how you bind the BindableCollection to the datagrid? I just dont get how it bind it just with the name. Im very noob at WPF and i really dont understand anything.
When you bind it without specifying any of the properties, .NET goes through and maps out what columns the properties should each be automatically. That is good for general models but for more specific ones you should map it out yourself like I did in the video.
Hi Tim, you used a "BindableCollection" as your binding source, as I understand... Would a List work as well, in case I want to bind to collection as binding source? And if it doesn´t, why not? What do I have to keep in mind, trying to bind an ItemsView to a collection? I have a Problem trying to bind a DataGridTextColumn in code-behind to a List . Can you please make a video on doing the same in code-behind, what you did in this video in XAML? I think, understanding how binding works is best using code behind. Thank you for your efforts!
Thank you for the excellent example Tim. Can you wire up for instance a click or double click event on the cell content of the datagrid and maybe have it filter the results of a particular column that you clicked in? For instance click in the Birthday column on a value with a certain year and filter the results with birthday's of that year.
Yep, you can check out the event list by looking in the properties window and viewing possible events when you have selected the grid or row definition. Then you can bind it to a method in your ViewModel.
Thanks
You are most welcome. Thanks for watching.
Tim does not x:Name define the name of the UI control? So if we use the same name for a property and a UI component, CM renders it? ( I hope I used the right technical words ) And if the UI control like TextBlock does not have x:Name option, we use Binding right?
Yes, CM looks at the name and binds it to the matching property (if it exists). We can also use the binding if we need to (usually special cases).
Your lessons are wonderful ... Thank you too much Sir.
My question … are you think to do lectures in analyzing “Big data” using Excel, depending on “data mining Excel AddIns tools”, and also by using the some intelligence techniques like “Genetic Algorithm Excel AddIns tools” thank you too much and I wish you always success
I'll be doing some things with Excel (exporting to and importing from Excel in C#) but I doubt I'll get into Big Data or data mining. That is kind of outside the scope of this channel.
Thank too much Dear Doctor
I hope that this will be within your interests in the future at least to deal with the data mining tool (AddINS) and how to add it to excel and deal with it and is it free and possible to be added at any time ...
Hi Tim,
I was playing around with Datagrid in this demo. One feature that came to my mind was how to implement Find and replace functionality as we see in Microsoft Excel. This was a practice and to do problem solving.
I bind datagrid item source to a datatable in my viewmodel. To implement Find and replace functionality,
i found one approach but couldn't achieve it. It is like this:
I compare a textbox value entered by user with one datatable column's value, and change those value with a new textbox value(say RepalcetextBox), but after I bound data to datagrid, I couldn't compare data column value with textbox value as now I have to deal with DataGrid data and not DataTable values.
Can you please tell me if my approach is correct or where I'm going wrong. Do you see think of any other approach I can achieve?
I would work directly with the models, not with the UI elements. So when you do a Find and Replace, don't search the DataGrid, search the List that supports the DataGrid. Then replace in them.
Hi Tim,
Thanks for the video. Please advise how to use numeric up down control to change the number of rows shown in the data grid. Thanks!
You would need to have the get for the list filter by the selected numeric value.
You are awesome
many thanks for the magnificent tutorial
but what is the BindableCollection is??
and how to bind data in excel to datagrid (number of columns & names are not know)?
thanks again
i mean in your example you have property for each column but when getting data from excel, i don't know how many columns and don't its type either
You would need to figure that out at some point. When you get data from Excel, you would need to put it into columns and rows. To use it effectively in C#, you would then need to assign that data to a strongly-typed object that has defined properties. Otherwise you can't do easy binding like this. You will need to do a more manual binding process.
@@IAmTimCorey first, many thanks for your fast replay
i do put the excel data in datatable, i hope this not breaking the MVVM pattern
but i can't have full control on it,i miss the properties to bind it as i wish
also, i found it too hard to create checkbox column and bind it to row selection , so i can only processing the selected data
i hope you can make more videos on this complicated control
i'm in this for more than three weeks, but progress is too slow
thanks
Thanks so much.
You are welcome.
Tim how to have a datetime control as its in the windows form
Great video. One question: while I see how the edits modify the instantiated model (data in memory), how would you trigger committing the changes back to the database?
Put a command that observes the change and saves it to the database, or trigger a save at your convenience (maybe when they leave the form).
Thanks man.
You are welcome.
Great Video Tim!! i was wondering if you have a video that explains all the different events on DataGrid such as BeginningEdit, PreviewLostKeyboardFocus, InitializingNewItem, CellEditEnding ... etc ?
Nope, I don't. They mostly explain themselves but that might be an interesting video for the more obscure ones.
Hi, Thanks for the videos but I think the wpf series is highly missing a tutorial for events (or event aggregation) on caliburn micro. Can you please make a tutorial on that?
You can see events and event aggregation in the TimCo Retail Manager series, where we have an API middle layer and a WPF front-end. Specifically, when the user logs in, it fires an event that opens up a new form.
Will there be more videos coming for this series?
This has been extremely helpful. Thank you for taking the time to make them.
Possibly. Let me know what suggestions you have for things you would like to see.
@@IAmTimCorey Awesome! I'd like to see how to exactly save edits from the data grid and working with multiple views/pages. I'm still new to WPF and MVVM so excuse my ignorance.
What would you recommend as a replacement for the Windows Forms PropertyGrid? I find it strange how there does not seem to be one in WPF when Microsoft very clearly has one built for their own use in several of their applications that utilise WPF, or so it would seem.
Off the top of my head, I can't think of one but I can look into it.
Great sets of videos I have learn a ton. I did have a question on the datagrid combox. I noticed that the down arrow is missing unless you click on the cell. Is it possible to have the arrow showing all the time? if so how?
That's because it isn't a combobox in view mode, it is a textblock. You can change the template to be a combobox in view mode as well, if you want.
Very clearly explained, thank you. I would like user have provision to sort and filter data grid columns like Excel, It will be great if you could share a link where it has implemented or guided how it has to be done. Thank you so much.
I don't have an example of this. Sorry.
Hi Tim,
I can populate the WPF Datagrid - is there more information about saving the row changes back to an object model that can be saved back to SQL Database Table?
That isn't a UI function really. I have videos on how to save data to SQL. They are what you need to save your data back to SQL.
This is very good! Thanks for putting effort into making this video. I’m fairly new to WPF and I’ve learnt a lot from this video. I have a question if you don’t mind... how would you do it if you’d have to highlight cells that have a certain value? Say, for example, a list of users having an “Active” column that can be “Yes”/“No” (or true/false) and you want to set the background colour to light green for all those having “Yes” in that column. Many thanks.
You would need to do a conditional check for each cell after each update and then update the cell's background color based upon the value.
Can we show only month and year in date picker . Is there any string format for that ??
Bdw great informative video . Thanks 🙂
Thanks for watching and posting a question.
Hi Tim, Thanks for the amazing Tutorial. I am currently building a Datagrid and it has a column that is supposed to provide a drop down with a editable textbox in case if the desried value is not in the drop down.
my datagrid is bound to a datatable. It takes in the value i enter correctly, but while displaying it splits the value into single characters and displays them as sepearet items. Would be glad to hear from you.
It looks like you are binding the ComboBox ItemSource to a single item. You need to bind it to a list of items (the items in the dropdown).
Hey Tim! Do you have any materials on how to bind this ComboBox to List that is outside of Person model? Like if the Addresses are just a list(taken and updated from database) and you can select for every person a address from there? Makes more sense, if i have one list of address and Person model holds only the Id to that address(as its done with the WinForms combobox). I have searched a bit but haven't found as nice tutorial as you do on these topics(i even started the C# mastercourse on your website thanks to these youtube videos). Usually when the code starts to scare me, then i know that there is a simpler way to do it...
Hi Tim, if I change values, or add a new line, does that automatically change the values in the object?
For example, if I have bound an Entity Framework Class to the DataGrid and I make changes in the grid, is it enough, just to call 'SaveChanges()' Method of the EF Framework?
Yes, changing the value changes the object.
Hey Tim...using caliburn micro (or anything else) is there a way to get the datagrid to refresh without code-behind? I have a form that creates the new item and a button in the datagrid that deletes it; but it's not refreshing. My Datagrid is is named the same thing as my bindablecollection.
You should be updating the grid by adding to the ViewModel, not by manipulating the grid directly.
@@IAmTimCorey Not sure I follow just yet. So I have a ViewModel (SettingsViewModel) that loads up a Model called LinkPatterns. this is getting data the same your your example does: DataAccess class that loads data into the LinkPattern model from the app.config file. I'm calling DataAccess from the SettingsViewModel contructor so it loads at startup. Datagrid is populated just fine there.
Based on your response, I think the problem is when I add a new link pattern, I'm adding by a method that writes xml to the app.config file directly. Soooo, basically nothing is going to automatically load this datagrid with the new entry until my VM opens again.
I'm not very advanced, but I think I can find my way around adding my new pattern to the collection, but won't collection have all of my previous records there? If so, I don't know how to only write the new one.
Hello,
Sorting on column-header click for the data template column doesn't work directly in this example, we need to set the SortMemberPath attribute to enable sorting.
Just for other beginners like me who face the same issue.
Thanks for sharing.
Nice!!!!!
Thanks!
These videos are very helpful, thank you.
1 small question, how can you make calculations with the rows of the datagrid so you can show them in another row?
Thank you in advance
I don't have an example to show you of that, sorry. Typically, you would use a third-party library for this, although it can be done manually.
Nice
Thanks!
Hello Tim,
Do you have any tips on how to use a listbox in MVVM?
It is very similar to a combo box. I have a video on the combo box so you should be able to do everything in that video but with a listbox.
When do we use binding alone, and when do we use a path please? Also do we have to use propfull or other types work with CM and XAML rendering?
Path is being explicit. Sometimes you need to be explicit when other parameters are involved or you have other properties coming in. In general, you don't need it but if you have a problem, adding it can't hurt and can sometimes be the solution.
@@IAmTimCorey Thanks.
Only WPF topics lastly Tim? No other arguments in the next videos?
I'll be doing other things very soon, I just wanted to clear the decks of a few WPF control videos that have been sitting there for a while. I know not everyone wants to use WPF.
Hi Tim,
I've been trying to bind my checkbox (inside a datagrid template column) to an event (both property setter and methods, neither worked), i tried everything i could find online for the past couple of hours but nothing seems to work. A regular checkbox works fine with the notifyOfPropertyChange, this checkbox doesn't though.
I tried UpdateSourceTrigger=PropertyChanged, RelativeSource AncestorType=DataGrid, and a few other things, with different combinations (all with IsChecked, as checked would give an error), but nothing worked yet
Hi Tim - Your videos have been so much help! I am able to use DataGrid with Caliburn Micro as you have described. What I am really struggling with is how to get the column index for a selected cell. I have tried every combination that I can think of for SelectedUnit = Cell with SelectedCells, SelectionChanged, SelectedCellsChanged, etc. and I have had no success linking my view and my viewmodel at the cell level. Any advice would be greatly appreciated. Thanks!
I believe the solution isn't to try to get the selected row by index but rather through the binding. Bind an object to SelectedItem and you should be set.
@@IAmTimCorey
Thanks Tim. I was able to bind a ViewModel property to CurrentCell and get the column index from the associated DataGridCellInfo. When Caliburn uses Name to bind a BindableCollection to a DataGrid, is it possible to assign property values to the DataGrid object programatically from within the ViewModel? I have tried but don't know how to access the DataGrid object from within the VM (I can only access the Collection). Thanks again for everything!
@@IAmTimCorey I tried doing that but the binding doesn't seem to work. Why could that be? I can only presume no item is selected when I push the corresponding button (although the line with the button is colored dark blue so should be selected...)?? Binding using SelectedItem with ItemsControl does work out well so it's not that I cannot work with the "SelectedItem" property and bind it to an Object.
Thank you so much sensei... I needed this..but I still have one more thing left ....it’s the totals row...I want to have a totals row below the last row...
Hmmm, I'll have to see if I can work that into a future video.
it would be nice of you if you could make blend tutorial.
It is on the list. Unfortunately, it isn't a tool I use much so it isn't easy for me to do something meaningful with it yet.
@@IAmTimCorey With blend you can save a lot of time.
Yep, I agree. I'm just not a designer so I haven't spent a lot of time in Blend. I need to really understand something before I teach it, which means I need to learn it better first.
Why are you using "." and not "_" when binding to a property of a property of the view model? Which one is the right one? Are they interchangeable?
I use a dot whenever I can but if there is a situation where the binding won't work with a dot (where it conflicts) then I use the underscore.
Hey Tim, you got some awesome and informative videos! I have a quick question, how would you set a button that would delete a row that the user selected from the DataGrid? I'm trying to figure out how to retrieve the data in that selected row to be used to pass a query to my SQLite database.
For example, following your video, I would click on a "Full Name" row and click a delete button that would retrieve all the data of that person (Birthday, address, etc..). From there, the rest of the code would use that data to fill in a delete query to a SQLite database.
Any advice would be appreciated!
I think you need to set up a model for selected row and then just remove that row when the button is pressed.
how can I pass the selected data to a textbox?
You would pass it to the property that stores the textbox data. I believe I do that in the ComboBox video but I'm not certain.
Hi Tim, how would I get all the displayed data out of that datagrid and into a sql server table? Coming from winforms I cannot use row.Cells[0] anymore
The ViewModel has the list of your data. That is the data you use to save to the database. You don't need to query the UI to get the data back.
Tim just a quick question. If i have a class with Lets say int Id set; get; string Name set; get; and Owner Person set; get; this class called PetModel right? then when i create a method to call all my pets in a DataAccess class i run a query of type PetModel and call my store procedure i get an error that says that i cant parse the column wich i have my Owner because its of type object and my sql table its an int. cant really figure how to solve that.. I would really apreciate if u find some time to answer me. Thanks a Lot.
This part of the documentation should be exactly what you need: github.com/StackExchange/Dapper#multi-mapping
Thanks Tim it really helped me!
Hi,
I've a problem with this type of binding. After the first binding, if i change in background some value of the collection the UI doesn't refresh the DataGrid values. I can see the new values only by clicking one of the columns header.
Did you use the same list type as this video? Also, you can have the item that is changed trigger an INotifyPropertyChanged too.
@@IAmTimCorey I'm using a bindableCollecion like in your video. I've a InstructionModel class with the property "Executed" to be updated.
public BindableCollection Instructions { get; set; }
public ShellViewModel()
{
Instructions= new BindableCollection();
}
public void AddInstruction()
{
Instructions.Add(new InstructionModel { Command = "DEMO", Executed = false }); //It Works!!
}
public void ExecuteAll()
{
foreach (InstructionModel item in Instructions)
{
item.Executed = true; //It doesn't Works!!
}
NotifyOfPropertyChange(() => Instructions);
}
______
In XAML File:
______
The DataGrid shows the result of "AddInstruction" method but not of the "ExecuteAll" method. Debugging I can see that the collection is updated with all the executed parameters to "true".
I fixed it implementing "OnPropertyChanged" method inside the "set" method of the "Executed" property of "InstructionModel".
@@gualto89 , Do you have the code for this fix ?
I have one question about data grids or other controls. If a person wanted to have several buttons and when you click on the button, then it runs a command on the view model, how can that be done with caliburn micro? I've done it before with old fashioned Command. However, I would prefer to be able to invoke a method without the commands. What I would want is when they click on an item, that becomes the parameter that gets sent to the method and even having the Can so if the validation fails, then the button would be disabled.
You can do that. The button can actually be in the model that you have a list of. You could also have the button send the row information on click I believe. Sorry, I don't think I have an example right at hand to show you.
Hi Tim, How to add a button column at the end of the DataGrid and assign a click event to each button in every row. I need to make a DataGrid that gets Factures from the database and I need to put a view button for each facture to view its details. Any help please. Thank you.
There are a few ways of doing it. You could put a method in your model that each button could call. You could also just have each button point to the same method and have it work on the selected row.
@@IAmTimCorey yes but how to add a button. to each row. PS: I can just create a Button btn = new Button() and set is parameters in windows form apps and add it to each row and simply bind, but how to do that in WPF. Can you help with that to??
My reply was assuming one button per row. When you set up your row template, include a button. Bind the click event to a method on your ViewModel.
@IAmTimCorey SORRYYYYYYY for the late reply. Here is the link for the best answer so far stackoverflow.com/questions/55498151/add-a-buttons-to-rows-of-datagrid-and-event-click-to-each-using-caliburn-micro-i/.
Great explanation, Is it possible to make a video on how to set DataGridTemplateColumn visibility via Binding using mvvm?
I will add it to the list. Thanks for the suggestion.
@@IAmTimCorey maybe u can teach me?
Hi, I have a question. I'm making a small Inventory system Project. I'm doing this with the MVVM framework. And in one of my views, I also using a bindableCollection to display all my customers. I also added some Delete and Edit buttons in case the user wants to delete the customer from the datagrid. I have is I would like to use some commands that are also bonded to some ICommand Classes to delete or edit some of those customers. The problem is I can't get those commands because they are not part of the bindable collection. I can only bind to the properties in my collections. What is the best way to do still use those commands? I thought of multiple item sources in order to get those commands but apparently, a Datagrid only allows one item source binding not multiple. Thanks anyway for the amazing content you give.
Tim, I am enjoying your courses! I have added a datagrid to a wpf form. The datagrid is displaying but there is no data in it. I can see the columns and the sorting button, but nothing below that. The data is in a model called ActiveAccounts. I can see the data in the watch window, but it doesn't appear in the datagrid. Data is coming from two different tables in the view, but I tried it with both models and both are the same. Can you suggest why this might be?
Ted
Are you auto-generating the columns or manually specifying them? If manual, try auto. If auto, check the list of model you are sending to be sure there is data in it. Also, make sure you trigger the NotifyOfPropertyChanged after loading your list if you are just filling it (try it either way).
@@IAmTimCorey Thanks, Tim. To start, I am Auto generating. The data is there. I am following the TRM course as the basis of the app. The view I am working on corresponds to the SalesView, but I have a combo box and a grid on it. The combo box is populated. I'm going to try a simple view with just a GridBox on it with only one list and see what happens. Ted
It is working now. Unfortunately, I don't know why. I will be checking in Team explorer to see what changed.
Team Explorer shows that the main change was to change the list from a BindableCollection to a BindingList.
Hi! Do You have a video there you show doubleclick in datagrid and get that row in viewmodel? Im using mvvm and caliburn micro
Aaaaahh it works... it was so easy tbh :) Love it!
Dumb question... where/what are the videos leading up to this? Building the VM and the M etc etc.. Definitely going to dive into that!
Not a dumb question. Here's the WPF playlist: th-cam.com/video/gSfMNjWNoX0/w-d-xo.html
Hi Tim, I appreciate your input in making concept of learning C# easier, since I've watched lots' of video tutorials you've posted there. They are mostly very clear and intuitive to get close with the idea. But I have one very big notice regarding MVVM-concept and it's regarding the Caliburn Micro: I would like to implement MVVM without Caliburn micro. Is there any plans to make some observable video with datagrids and comboxes (for example) on this topic.
Thank you in advance.
Hint: When you go to my channel page (th-cam.com/channels/-ptWR16ITQyYOglXyQmpzw.html), use the SECOND search option which is under the Subscribe/Unsubscribe button to search my channel. If you look for 'MVVM', for example, you would find these items to address your needs - th-cam.com/video/zvyQNuuTqks/w-d-xo.html (Datagrid) and th-cam.com/video/nKJ_XDoAdtY/w-d-xo.html (Combobox)
@@IAmTimCorey thank you for the reply, I'll try it out. And once again thank you for the great input.
Hey Tim
I just want to add data (your api exercise data
) and populate in in the DataGrid.
Before it was easy cause u could create the columns and select a datasource. I have no idea how to insert simple data in this datagrid...
You start off with a complex data source
The data source isn't really important. You can just cut that part out and put in sample code or call an API. Up to you. You just need a List with your data but where it comes from doesn't really matter.
Hi Tim, thank you again. Your tutorials are the best!
Is there an easy way to display only the persons that are alive? Even if in the Collection are people which aren’t.
You could query the data before loading the list so that the list is only the records you want to see.
Hi Tim, thanks for your video - super helpful and easy to follow. One question I have that hasn't been mentioned is - is it possible to bind datagrid to not just the properties of a class but other data as well? Say in the Person class, in addition to the the properties you have now, there is also a "public Dictionary Families" that holds the title and names of his/her families as keyValuePairs like . Is it possible to do something like {Binding Path = Families["son"]}? If you have other tutorials that get into binding more please direct me to those. Appreciate your help!
That would be less than ideal. You can bind to a list or even a Dictionary but trying to bind to a specific entry in a Dictionary isn't usually done. Usually, you would surface that into its own property.
@@IAmTimCorey Thanks Tim! I'm rethinking the structure of my class. :)
Thanks Tim,
Great videos!
Im am looking for changing the background color of a specific cell,
Every cell contains a object Bag.
This Bag has a TrialId.
I want to give every cell with TrialId "1" the same background color.
the same for every trial.
So that i have a nice overview of all the cells with the attached trial.
Do you know if i can do this in a datagrid, or maybe you have a different solution.
Thanks for helping!
I don't have sample code for that, sorry.
Hi Tim,
I have data grid on the page....and I have enabled Canfilter property so when I mooise curser over grid column head I can see a tiny text box to filer the perticular column values...so here we ge on my question...
When I click on the text box n type any character the data grid will get filtered ..but the text in the textbox which in next to grid header will remains untill unless we manually clear it....so here I want to clear that text when we click on cancel button(it's one of the button on my screen)...can you please help me on this ...
Thanks
The textbox is bound to a property so when you hit the cancel button, clear out the property value and it will clear out the textbox.
Hi Tim
Great videos. A question, how can I bind a Dataable to my grid using MVVM
I don't have an example of that, sorry. DataTables are a lot messier than c# objects.
Just use the ItemSource property and Bind the property with ItemSource with an extension of ".Default".
For eg : ItemSource = {Binding MyProperty.Default}
Hi Tim,
from this video we can see that the data is static and if you don't mind I want to know what if we want dynamic data in the datagrid I mean the user can input like microsoft excel so we don't need to initialize the data first. thank you and god bless you
You can't really make a grid like Excel. You need to know what to do with the data once it is input.
thanks!
You are most welcome. Thanks for watching.
Thanks Tim, Very interesting as usual, Then I have a question , I would like to use this Datagrid to a List extract from a SQL db using your previsous video with Dapper. but once the user start changing for example your check box from true to false how to update the database the smarter way ? Thank you very much for your help
And If I can suggest a topic for one more video in your todo list is about WPF image display or management or arround this after like zoom or so :)
Regards
You can call a method on a number of different events. For one, you could call a method on change of the row. Another idea would be to call a method on change of a specific field. Either way (or others), the method could save the row to the database right away. You could also save all dirty (changed) rows at the end when they submit the form.
As for the image in WPF suggestion, I'll keep that in mind. Thanks.
Okey, Thanks for the Help !
What should I do if I want to display dynamic data? For example I don't know if I have 15 Colums or 120, it depends on the content in the database
That's when you use the auto for the column display. It will handle setting up all of the columns.
Hi Tim
I am trying to create a textbox that is linked to a combo box that has a list which is taken from a database and what I need to happen is as I start typing in the Textbox the list of items in the combo box is reduced based on what I type in the textbox. Is this even possible in WPF?
Yep. You will need to use the KeyPress event or something similar to then apply a filter to your combo box but it is definitely possible.
@@IAmTimCorey Thanks Tim
hi
what is the best way to array control in wpf mvvm in two dim ( in X & Y direction ) to create table of data other than datagrid
Hello Tim, thanks a lot for this valuable content.
I have one question: When do you use just {Binding FullName] and when {Binding Path=FullName} ?
as far as i know, both mean the same thing, except that one is more verbose
@@pexoto5093 - Correct
Thank you for this video . It all works fine except one thing I am trying to achieve and it doesn't work. I want to remove a record in a datagrid using a button that is actually in the grid itself. Though the "SelectedItem" property of Datagrid doesn't seem to work properly. I see other people have a problem with selecting a row in such a grid as well...
You need to make sure you are removing the record from the list. It should work fine but you might need to play with it a bit.
@@IAmTimCorey I'm playing with it. It seems the selecting goes fine! The problem lies indeed in the removal. I'm going to do some further experimentaion with it and I'll let you know if it works. Thx for this very fast reply!
@@IAmTimCorey OK it works now if a put a button OUTSIDE the datagrid. Then when I select a row and press the button OUTSIDE the datagrid the row goes away like it should. But when I click the button INSIDE the datagrid and the corresponding row the "DeleteRow" event does not seem to get fired... Wonder why that is.
@@IAmTimCorey Hey. There is one thing I'm really wondering about. What's the purpose of the "Models" folder in MVVM ? Since in this video e.g. you use a folder "Models" uotside Caliburn Micro. Why is that? When do you use the folder "Models" inside the WPFapp itself?
I have a question. How can i make it so a column only Accepts currency values? I'm pretty sure it will be with the edit template but I'm not sure how.
is there a video before this one? i have to create a table and fill it with data from tsql and this is what im looking for
I show you how to create tables and populate them in the TimCo Retail Manager series. I also have a course titled "SQL Developer from Start to Finish" that would be really helpful.
Dear Tim ,Thank you for the amazing Videos, and also sharing knowledge
I am a VB windows developer for more than 10 years but know i have to move to WPF with C#
and your examples helped me a lot to do that.
I am planning to develop a Point Of Sales system with all the functionality of POS regiments like Bar code,print a Precept and Touch screen.
would you recommend me to use MVVM with Caliburn Micro or use othe tools for that system.
Your recommendation will be highly appropriated, Thanks again for every thing.
I definitely recommend Caliburn Micro. It is a great tool for the job.
@@IAmTimCorey Thank you very much for your recommendation
Before I get into this video: MVVM and Corbin. I am trying to do everything with just WPF and Dapper (You sold me on Dapper in your 'accessing SQL' video). Will this video confuse me via "GREAT, BUT... If you are trying to do this directly with Dapper and not adding in MVVM/Corbin, then this may not be useful to you..." ??? Thanks Henry.
I think you are referring to when I said MVVM and Caliburn, as in Caliburn Micro. You can see the intro to that in my WPF with MVVM video. This video and a few other WPF videos use the MVVM framework but setting up MVVM on your own is a pain so I use Caliburn Micro as my tool for MVVM since it is easy and powerful.
Hi Sir,I am new to both WPF and MVVM so please pardon if this is a silly question.
I am having a datagrid with two groups inside it say Male and Female. It is bound to Collectionviewsource which is an observable collection of persons. I have grouped based on Gender. If I drag a person in Male group to female group, I should be able to see dragged item in female group.
Let's say I have a collection of Persons: Vinay, Vijay, Nandini, John, Sukanya etc. These persons are grouped by genders: Male and Female.
Within a datagrid, I would like to drag a person from one group to another. I want to achieve this in MVVM way so that when I drag and move person ,property or collection in viewmodel should change.
All I need are guidelines to follow. Any help would be appreciated.
I'll see if I can cover some of this in a future video.