I have a DataGridView with 4 columns, one of them being a drop-down (ComboBox) column. The values in this column must be distinct so once a given drop-down values is selected in a row, I'd like it to not be available in any of the drop-downs in other rows. If a given value is unselected it should show up in the drop-downs again. I found a few articles with similar examples (1,2,3); however, all of them seem to involve subscribing to an event and manually populating the ComboBox.
Is there a way to accomplish this with databinding alone (maybe to an IEnumerable that's basically a all.Except(selected) Linq query)?
If databinding alone isn't enough, is there a better way to do it than the examples I found?
I'm a bit new to WinForms development so having trouble telling apart good advice from "yeah...that'll work, sort of".
I'm afraid your searching so far is correct - there is no better way to provide different lists to comboboxes in the same DataGridView column than subscribing to events (usually CellBeginEdit and CellEndEdit and then setting the DataSource for an individual DataGridViewComboBoxCell).
By way of evidence of this, I'll point you to the excellent DataGridView FAQ which was written by Mark Rideout, the DataGridView program manager at Microsoft. The FAQ has a full solution to your problem which is very similar to the links you post.
Related
I am struggling some time with checkbox control in WPF. What I am trying is to to make some kind of filter.
1. So first I need to fill the checkbox control with the database items
2. Second I need to check if anything is checked
3. Third if anything is checked I want to take those values and use them to search through the database
4. Should I use only checkbox control for this or should I put it in some container or a listBox?
I have find many topics here that are mentioning this stuff, but I couldn't manage to find the complete answer, only lot of parts that are not compatible with each other. I would really appreciate if someone explain to me how checkbox in WPF works.
If you have multiple values and you want to display multiple CheckBoxes, one for each of them, then you will need to use a ListBox and have the TemplateItem a CheckBox. This way your collection of items is bound to the ListBox, and for each item in the ListBox a CheckBox is shown.
So to get each of the values after there is an additional step if your doing MVVM and don't want to touch the UI. What you do is create a wrapper class that sits around your class and has a extra property for the IsChecked data. This way you can get the checked state without touching the UI.
I have an example of this on my blog:
Checked ListBox in WPF
To check which items are checked you just need a simple LINQ query. So if you use the example there from my blog then you should be able to do something like this:
var checkedCustomers = Customers.Where(w=>w.IsChecked).ToList();
Here's my issue : I need to build a C# application with WPF where the users can select numerous lines from a DataGrid. But, despite the fact I put the selection mode to "Extended" I'm only able to select a single row from the GUI.
I thought I could circumvent this problem by programmatically select the row the user clicks, but again I can only select one row at time ! I searched a lot on the internet but didn't find a simple way to select multiple rows in a datagrid
I'm a beginner with WPF and I'm not very good with DataBinding and MVVM pattern, so if the the answers could be simple it'd be perfect !
Thank's a lot !
I finally used the checkboxes method, referring to this article : http://www.scottlogic.com/blog/2008/11/26/multiselect-datagrid-with-checkboxes.html
It works great and it's really easy to implement. At least the part with the checkbox. I put the CanUserResizeRows property to false, which resolved the issue with the gripper !
Changing the selection mode and selection unit should most probably fix your problem. It's working in my case.
In you XAML, set you following DataGrid attributes:
SelectionUnit="FullRow"
SelectionMode="Extended"
This should work.
You can Add Template column for CHECKBOXES for selection.
refer this Multi-select ASP.NET datagrid to get complete solution.
By default, you need hold shift and click to select multipe rows, really make no sense. Most people chose the check box approach. But wpf don't give you a simple option.
I want to develop an application which uses a DataGridView for showing the data from the table. And I want to add the filter row to the DataGridView. It means when the user clicks on the filter button then the DataGridView should add an empty row at the beginning of the DataGridView. And if the user inputs some data, depending on the fields which present in the DataGridView, then the DataGridView should provide the quick filtering related to the input in the specific cell input.
Can anybody help me do this?
It's hard to tell from your question what exactly you're trying to do. In general, people are not going to give you a complete, working solution as an answer. You'll have to do most of the programming work yourself; we're only here to help out if you run into a snag along the way, not write your code for you.
In the future, please try to put more effort into your questions than simply posting your requirements.
That being said, you might want to check out these sample projects:
DataGridView Filter Popup
DataGridView Filter Popup (yes, these are two different articles, despite having the same name)
Datagridview with filtering capability
A Filter Dialog for a DataGridView
DataGridView Filtering User Control
This may help
how to filter datagridview with user control popup
I want my ListBox to have columns, and one of those columns have to be a clickable URL.
How can I achieve this?
You can't do it in a ListBox. You can create your own control, or settle for another existing one. Based on the question, I'd guess you're not yet at the stage where you're creating your own controls. That takes a pretty good understanding of existing controls and the way they work under the covers (but a google search for creating Winforms Controls should yield plenty of instructions.) Edit added It looks like te 4th and 5th links in combination on that google search should get you what you need. You can create your own user control and then do an array of them)
As far as for other possible alternatives, have you considered a DataGridView? A DataGridView can have a hyperlink and it can have checkbox columns, so this would be one possible alternative.
Here's a link for having a Hyperlink column in a DataGridView.
Well, it is possible by using the CustomTabOffsets property (unreliable) or the DrawItem event. And implementing the MouseDown event to find out if that particular 'column' was clicked.
But there's little point, a ListView control with View = Details gives you the same functionality.
How do I display a DataGridView within a cell of another datagridview in C# forms app?
How would I have to handle Sorting & value changed if this possible?
That is the only way I can display data to make some sense.. Think of it like I have a task column and dates column. Under the dates column I have a list of things to be done. These date columns are dynamic & there might be multiple date columns
That sounds like a difficult interface to use, have you considered some kind of tree control?
If you're determined to use data grid views, look at customizing data grid view columns and cells. You need to declare custom subclasses for the column and cell behaviour that you want. I don't know if it's possible to do what you want, but that's where I would start.
This is a suggestion since what your asking I do not think is possible with the built in DGV of .NET.
Using custom controls made by professional companies that provides a DataGrid with the capability of hierarchical data. For example a row can be expanded to show multiple entries (the multiple entries can be an entirely different table containing completely different columns even). Here are a few options that you can check out.
Infragistics WinGrid
Component One
There are a few other places/companies that make great .NET component packages that provide added features to the existing .NET components.
http://blogs.msdn.com/markrideout/archive/2006/01/08/510700.aspx
Found a link where hierarchichal datagrid is implemented.
Now, I have to either modify the control, or settle for hierarchichal gridview!
Hope this helps someone. Will update later