I just want make my DataGird group editable.
I use this code to set the group in .cs
ICollectionView oView = CollectionViewSource.GetDefaultView(oDatas.oLstImg);
oView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(CDataScriptImg.sGrp)));
But the CollectionViewGroupInternal.Name was ReadOnly
I cannot set the TwoWay for directly edit the selected group name.
Any idea how to do that?
Thanks in advance
Eric.
Related
I am coming from programming with WinForms and now start to change into WPF. In WinForms I could easily bind a DataGrid before Runtime, to adjust the columns without coding everything.
The WPF-Datagrid has the property "ItemsSource", but I don't understand how to bind it in editor. I have already a DataSource which refers to a SQL-Database, but it will not be shown in the property window.
How to do this?
Screenshot
you have to expose your collection as a public property
make it visible in the xaml (namespace include)
set up your DataContext correctly
create the binding in XAML and set up the columns, like here
If you want to see the changes in your collection online, you have to use ObservableCollection<>
I have a datagrid which has an item source of observablecollection and I want to 1 column to be saved int the observablecollection and not show it to the user in the data grid.
how can I do that?
You can hide the Column in the code behind like this:
YourDataGrid.Columns[IndexOftheColumn].Visibility = Visibility.Collapsed;
Alternatively if you want this to be xaml-only, you should set AutoGenerateColumns to False and define custom columns in your Xaml.
I have a UserControl that has a DataGrid in it filled with members. The DataGrid.ItemsSource is bound to an ObservableCollection on the model. The DataGrid.SelectedItem is bound to the SelectedMember field on the model. The SelectedMember._set calls NotifyPropertyChanged and the event calls SetValue() for the exposed DependencyProperty.
This UserControl is on a page. That page has a viewmodel too. I'm trying to bind the UserControl.CurrentMember to the viewmodel.SelectedMember but it's not changing. I can bind the CurrentMember.MemberName to a textbox and the box fills with the member name so it looks like the UserControl is exposing the DependencyProperty correctly. But if I bind to the model it doesn't update.
I can't find any cross bindings. The bind to the TextBox works fine. The field on the page model is new so there's nothing bound to it.
What could be the problem? Does the field on the page model need to be a DependencyProperty? The compiler would give me an error if that were the case.
I'll try and get a code sample but it's so ingrained I can't just post a couple of lines of code.
Tom P.
After combing the code and trying to replicate the problem in a new project I found the problem.
In the UserControl I set the DataContext to the Model. But the UserControl.DataContext gets overwritten when I put it on the page. What i needed to do was name the MainGrid and set the DataContext of the MainGrid to the UserControlModel. MainGrid, being private to the UserControl, won't get overwritten. Now it works wonderfully.
I have Silverlight DataGrid, I want to make some rows enable/editable and some disable or read only.
It is not possible to set entire rows to readonly in a DataGrid. You can however set the control containing your datavalue to readonly; just bind the ReadOnly property to your rowvalue's readonly property.
Is there a way to make column of cells in a Silverlight datagrid be readonly in editmode with C# code instead of setting up a entire datagrid as a template in a resource file?
UPDATE
Found an example piece of code -
http://forums.silverlight.net/forums/p/17483/58189.aspx
In the response by slhungry midway into the thread. He has example code written as a XAML template. Can you write this in C#?
Well, you can certainly create DataGridColumns programmatically in your codebehind and add them to your DataGrid:
DataGridColumn myColumn = new DataGridColumn();
Then you can easily configure the properties:
myColumn.Header = "tyndall's New Column";
myColumn.IsReadOnly = true; // All cells in column will be readonly
You can also programmatically set up binding in the codebehind, if you wish. Finally, you can add this column to the datagrid:
myDataGrid.Columns.Add(myColumn);
Does this help answer your question?