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.
Related
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.
I'm watching at this page:
http://leeontech.wordpress.com/2010/02/01/summary-row-in-datagrid/
But they're using silverlight. I'm trying to create that user control to use it in a WPF C# application. I mean, not using Silverlight. But I can't find the namespaces: GroupHeader
I'm having a hard time with this. Thanks in advance.
Okay listen, you can totally do this, and in some scenarios I even recommend it.
Using a CollectionViewSource you can easily group your data. In the HeaderTemplate you can even use an Expander (or make your own) and get the animation you might be wanting. Here's a link to a sample of this: http://jerrytech.blogspot.com/2010/06/wpf-data-presentation-step-by-step.html
Using an ItemsControl, you can easily present your groups and details. In the ItemTemplate you can use styles make this look like a grid (if that is really what you want). You can also shift the style based on the type if your collection has more than one type of object in it (eat that datagrid!).
You can wire up your column headers (which will really be custom objects, right?) and handle all the sorting and stuff like that. They will look just right! Not like datagrid WinForm column headers!
Here's what's hard (not impossible, but more coding).
User-resizable columns.
User-rearrangable columns.
New record using bottom, empty row.
Paste from Excel (doesn't work right in datagrid either).
Select Row, highlight Column header.
That's it.
In lots of situations, this is really nice.
For the most part, I cannot stand the datagrid. Too restricting on UX.
I don't think you're not going to be able to get a silverlight control working in WPF.
Adding a footer row to the WPF datagrid is something a lot of people have complained about; it's ridiculous that it wasn't included out of the box.
See this thread from MSDN
Having been through this myself, your best bet will probably be to bite the bullet and use a third party control. It sucks, I know.
Lasttime my question may not be clear.So I comeback with same clarification to get the answer.
I develop one small Windows Application.
In C# coding time while I press Ctrl+F then I can able to see Find Window.
Similarly I want to have a serch to my DataGridView, and its DataSource is MyTable1. When the user presses Ctrl+F then I would like to do search and locate on Particular Row-Column in DGV's DataSource column.
Is it possible? Or any other way?
Thanks For Ideas
Here's a link with a simple sample of DataGrid search and highlight.
the data table has a defualtview property, you can use the filter property to apply the search. its like sql but only with the part that comes after the where
I have a form which has a Combo Box Control. I have selected the drop down style property to DropDown. I have also set the DropDown Width to 250.
I have set the auto complete mode to suggest and the auto complete source to listitems.
it works absolutely fine when i click on the drop down. but when i type in somethin, the auto complete mode activates a drop down which has a small width.
any help appreciate.
i wanna know how to increase the width of the auto complete drop down via code so that the list items are viewed properly.
I am using C#
Yes, this is by design. ComboBox uses the SHAutoComplete API function to implement the autocomplete feature. Note the declaration, the function takes a handle to the text box portion of the ComboBox. As such, it has no idea that it is actually providing autocomplete info for a ComboBox instead of a TextBox. Accordingly, there is nothing it can do to compensate for the non-standard dropdown width you use.
Well, that explains why it doesn't work. Fixing it is technically possible but quite ugly. You would have to run code in the KeyUp event and use EnumTheadWindows() to find the autocomplete window handle. Then you can use SetWindowPos() to make it larger. There is already code similar to this in ComboBox.cs (AutoCompleteDropDownFinder.FindDropDowns), use the Reference Source or Reflector to help you get this right. Good luck!
EDIT:
I removed my first suggestion to come up with a new link:
Actually its possible to control the width of the Autocomplete dropdown box, but its a little bit tricky and involves using win API extensively ...
Combobox too small when doing Suggest
Maybe this article that I wrote on Codeproject might help you in relation to the combo-dropdown boxes and a way that I hacked this...
I have 2 questions concerning C#.
1) I have a dropdown menu with several items in them. They are clickable, but when I click one, the older clicked one stays selected. Click another and the 2 original ones stay selected, and so on. I don't want this. What I want is that when I click one of the dropdownitems, that one is that selected one and the others are not.
2) I have a listview items on a winform. I loaded some string elements into it from a file. Now what I want to do is to be able to edit those strings and even add strings, just by clicking on the rows in which the data goes.
I've checked google and MSDN for these problems, but nothing helps, so I turn here.
2) The ListView does not support that type of action. You can roll your own (pain in the #$$), or perhaps a DataGrid would be better suited to your purpose.
EDIT:
This link may help
This one too
For #1 I'm a little confused. If the DropDownStyle isn't set to simple something strange is occuring. It's not much but maybe you could try recreating the control.
For #2 the easiest solution I can think of is to set a TextBox to be equal to the selected text value from your listview. After that write a little function to update the selected index of the listview with the edited text from the listview.
Please comment if you have any more information about #1.