I would like to create an input DataGrid - an empty set of rows with the column headers that can be filled with data by a user and then saved to a database. The DataGrid will not be therefore used to display data but acts like an input field. The behaviour would be similar to the one of Excell. The problem is that if the DataGrid has no data provided for it, it is not visible in the application and the user cannot enter anything. Is the DataGrid a good choice? How can this sort of functionality be implemented with a different control? I would prefer to use the DataGrid tough.
Thanks a lot for any help on this.
You can enter data in a DataGrid even without provided data at the start of the application. You just need the correct bindings for your ItemsSource, and set CanUserAddRows to true. Also, the class that corresponds to a row of a DataGrid must implement a parameterless constructor.
Related
i want to immitate the behavior of multiselection of items (eg. in a list view) and their appearence in a PropertyGrid. So, obly the same properties are shown and values set in the grid are set on all multiselected properties.
I have created a listview with some datatemplates and have in another listview some data(with databinding). Now i want wo have a multiselection on the listview with the data and have the properties shown in the another listview like in a propertygrid.(explanation: The ProprtyGrid is still not available in WPF and if has not the flexibility of showing data the way i need it)
So, how do i need to prepare my data to be shown in the list propertygrid-multiselection-style? Is that even possible???
Greets,
Jürgen
I'm not sure if this question is still active, or what not. But I have found a solution that works for me - and I need somewhere to share it.
The first issue you are going to have solve is selecting the items, ie. multi-select. See my tip here that explains how to do that.
Next, I guess its basically binding to listview's selectedItem property and how you want to update your propertyGrid based on changes to the selectedItem prop.
Hope this helps.
I have a DataGrid that is bound to a List (ListOne). Inside the grid I'd like to display an extra TextBox that contains fields found in another Class that is not the same as the Class used in ListOne.
I've done this before with a ComboBox using the DataGridTemplateColumn, the problem is I'm not sure how the Binding would work when using a TextBox?
ListOne contains code and description which is bound and displays correctly. My SQL Stored Procedure returns extra values using a Join, which I'd like to display as editable fields ListOne.
Any ideas?
You should probably try to bind the DataGrid directly to the joined data as i imagine that doing joins directly in the cells may be difficult and round-about.
I'm new to Silverlight, so this might be a simple question to answer. I have a grid (not DataGrid from the toolkit), so that data displayed in it can be easily tabulated. I want to bind the grid to a string array that never changes, hence the number of rows and columns in the grid will not change either. I see that I cannot specify a template like I can for a ListBox (ListBox.ItemTemplate) and I don't want to define each row and column explicitly (with a TextBlock in each one of them) in XAML. And I also dont want to generate rows and columns dynamically in code behind as it is not blendable. What's the best way to do this?
You might like this post
I'm looking to create a WPF textbox control that acts similar to the email recipient textboxes in Outlook (the To, Cc and Bcc inputs). I don't necessarily care that much about auto-completion (i've found millions of examples for that), but what I'm really struggling with is how to have delimited text entries in the textbox behave as entities the way they do in Outlook (once a recipient you've entered resolves, that text becomes an 'entity' which you can click to select, right click to get a context menu, etc. it's not longer 'plain text' in which you can place your cursor)...
Does anyone have any high level ideas how to accomplish this? Know of any existing examples (I've googled for hours)?
Thanks so much in advance,
Michael.
My rough thought process would be this... (note: I'm not actually coding it, so my details may be a little off...).
High level behaviour:
the type of data in your control is a list of items which aren't selectable. Therefore your control is, approximately, an ItemsControl (in terms of visual/XAML, it's an ItemsControl with a WrapPanel style layout and very simple TextBlock for the item template).
when your control gains focus, you need to switch the template to be a TextBox
when your control loses focus, you need to split the inputted text and convert it to a list for display.
Therefore, thinking code:
you need a UserControl, possibly derived from ItemsControl. That gives you basic behaviour to represent a list of items.
you need a custom DependencyProperty on your control that represents the delimited string.
when the string property changes, you need to parse it and replace the list of items in the control.
when the list property changes, you need to replace the string property with a suitably-delimited list.
In terms of code-behind, that part should be pretty simple. Then, for the XAML template...
you need a base template that displays your Items property as a list, using the WrapPanel layout mentioned above.
you need a trigger that replaces this template when the control has focus.
the replacement template should be a TextBox that is bound to the string property of the control.
the default binding behaviour on a TextBox will only push a new value when the TextBox loses focus, so you need to think about whether you want to make, say, an "Enter" keypress move focus (thus reverting the template to the list version - when the string property's value changes, your codebehind will update the list).
This should give you the basic behaviour. You should be able to bind either the list property or the string property from outside of the control, though you may have to be careful about what happens if you bind both properties since there's a two-way dependency between them...
I'm using the WPF DataGrid, and I'd like to know if there is any way I can access the DataGridRow's RowDetails programatically.
For example, when the user selects the row, I'd to grab some data from somewhere (say, a database), and display it in the RowDetails.
All of the examples I've seen tend to just display some extra bound data that isn't included in the columns for the row.
You could display some extra data but lazy-load it on SelectionChanged.
It usually is not easy to work directly with the WPF controls, they are not really meant to be used without a backing databound model.
If you have all the data in list of objects (or something similar) then you can do all sorts of fun things. I'm using a WPF Datagrid in this manner, and when a user selects a row, I think populate an editor control above the grid with the row item plus additional details.
That said, there's nothing stopping you from adding in additional information in the grid that's normally hidden and a trigger on row selection to show the additional data
you can use the following code
DataRowView row = (DataRowView)MyDataGrid.SelectedItem;
string strName = row.Row["Name"].ToString(); //where "Name" is the column name