EditItem is not allowd for this view - wpf

<DataGrid x:Name="dataGrid"
ItemsSource="{Binding}"
AutoGenerateColumns="False"
IsReadOnly='False'
Margin="1,3,6,3"
Height='135'
Width='180'
>
<DataGrid.Columns>
<DataGridTextColumn Header=" Numbers" Binding="{Binding name}" />
<DataGridTextColumn Header=" Numbers" x:Name='Lnumber' Binding="{Binding Lilies_number}" />
</DataGrid.Columns>
</DataGrid>
When I run the project , always , I have got [EditItem is not allowed for this view]
dataGrid.ItemsSource = Data.ctxSvc.GetAllTheLiLies();

I found the anwer, when I added ,
EnableRowVirtualization="True"
Is working fine,
<DataGrid x:Name="dataGrid"
EnableRowVirtualization="True"
ItemsSource="{Binding}"
AutoGenerateColumns="False"
IsReadOnly='False'
Margin="1,3,6,3"
Height='135'
Width='180'
>
<DataGrid.Columns>
<DataGridTextColumn IsReadOnly='True' x:Name ='Lname' Header=" Name " Binding="{Binding name}" />
<DataGridTextColumn Header=" Numbers" x:Name='Lnumber' Binding="{Binding Lilies_number}" />
</DataGrid.Columns>
</DataGrid>

Related

Typing Text into DataGridTextColumn doesn´t work

.. but pasting text does.
What could be the reason?
<DataGrid AutoGenerateColumns="false" Name="dataGrid" InitializingNewItem="dataGrid_InitializingNewItem" ItemsSource="{Binding SchadwagenVorgänge}">
<DataGrid.Columns>
<DataGridTextColumn Header="Bezeichnung" Width="*" Binding="{Binding Description}" />
<DataGridTextColumn Header="Sortierposition" Width="Auto" Binding="{Binding SortOrder}" />
<DataGridCheckBoxColumn Header="Umstellung" Width="Auto" Binding="{Binding ChangeOver }" />
</DataGrid.Columns>
</DataGrid>
Try something like this:
<DataGrid AutoGenerateColumns="false" Name="dataGrid"
InitializingNewItem="dataGrid_InitializingNewItem" ItemsSource=" {Binding SchadwagenVorgänge}">
<DataGrid.Columns>
<DataGridTextColumn IsReadOnly="False" Header="Bezeichnung" Width="*" Binding="{Binding Description}" />
<DataGridTextColumn IsReadOnly="False" Header="Sortierposition" Width="Auto" Binding="{Binding SortOrder}" />
<DataGridCheckBoxColumn Header="Umstellung" Width="Auto" Binding="{Binding ChangeOver }" />
</DataGrid.Columns>
</DataGrid>

How to work on control inside Datagrid in WPF?

I m stuck in minor issue,which become time consuming as per my project concern,i am using datagrid in my wpf project in which my requirement is to show payment button only when status is "Not Paid",here i had use DataGridTemplateColumn in which i m using Button and on grid only i m getting status of payment.
Here is my xaml File
<DataGrid Name="gridInvoiceList" SelectedItem="{Binding SelectedDetails}" ColumnHeaderHeight="35" ItemsSource="{Binding ItemsSource, ElementName=pageControl, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" CanUserAddRows="false"
HorizontalAlignment="Left" AutoGenerateColumns="False"
Width="978" RowHeaderWidth="20" RowHeight="25"
CanUserSortColumns="False" SelectionChanged="gridInvoiceList_SelectionChanged" Height="220" LoadingRow="gridInvoiceList_LoadingRow" SelectionMode="Extended" >
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Width="160" Binding="{Binding FullName }" CanUserSort="True" IsReadOnly="True" />
<DataGridTextColumn Header="Total Amount" Width="150" Binding="{Binding TotalAmount,ConverterCulture='en-GB',StringFormat=-{0:C}}" CanUserSort="True" IsReadOnly="True" />
<DataGridTextColumn Header="Invoice Date" Width="200" Binding="{Binding InvoiceDate}" CanUserSort="True" IsReadOnly="True"/>
<DataGridTextColumn Header="Payment Status" Width="220" Binding="{Binding PaymentStatus}" CanUserSort="True" IsReadOnly="True" />
<DataGridTemplateColumn Header="Pay" Width="105">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="Pay" HorizontalAlignment="Center" VerticalAlignment="Top" Name="btnPay" Click="btnPay_Click" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Print" Width="105">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="Print" HorizontalAlignment="Center" VerticalAlignment="Top" Name="btnPrintInvoice" Click="btnPrint_Click" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
I had use some code from reference code which had not fullfill my requirement
You can use a converter to achieve that. But I'll you show you the simplest, easiest way:
Create a property:
public System.Windows.Visibility PayButtonVisibility
{
get
{
if (PaymentStatus == MyEnum.NotPaid)
return System.Windows.Visibility.Visible;
return System.Windows.Visibility.Collapsed;
}
}
Then bind your button visibility to it:
<Button Content="Pay" HorizontalAlignment="Center" VerticalAlignment="Top" Name="btnPay" Click="btnPay_Click" Visibility="{Binding PayButtonVisibility}" />

Daughter DataGrid.Columns fill all the available width

There is my layout:
<DataGrid x:Name="BooksGrid"
DataContext="{Binding WorkingBooksSet, Mode=TwoWay}"
ItemsSource="{Binding}"
RowDetailsVisibilityMode="VisibleWhenSelected"
AutoGenerateColumns="False"
VerticalAlignment="Top" HorizontalAlignment="Stretch"
ColumnWidth="*">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Id}" Width="Auto" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Title}" />
...
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<DataGrid ItemsSource="{Binding Publications, Mode=TwoWay}"
AutoGenerateColumns="False"
VerticalAlignment="Top" HorizontalAlignment="Stretch"
ColumnWidth="*">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Id}" Width="Auto" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Publisher}" />
<DataGridTextColumn Binding="{Binding ReleaseYear}" />
...
</DataGrid.Columns>
</DataGrid>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
And it's a window
As you can see, daughter DataGrid for some reason has not filled all the available space, instead made ​​them narrow. Moreover it is prohibited to manually resize the columns.
I do not understand this behavior, especially as the "parent" DataGrid displays correctly with the same code
Add * width to one of the columns in your child DataGrid.
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Id}" Width="Auto" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Publisher}" />
<DataGridTextColumn Binding="{Binding ReleaseYear}" Width="*" />
...
</DataGrid.Columns>

Why can I select a row in one data grid, but not the other?

I have two DataGrids:
<DataGrid Name="grdDailyOne"
AutoGenerateColumns="False"
CanUserResizeRows="False"
CanUserResizeColumns="False"
CanUserReorderColumns="False"
CanUserAddRows="False"
CanUserDeleteRows="True">
<DataGrid.Columns>
<DataGridTextColumn Header="From"
Binding="{Binding From}"
MinWidth="100" />
<DataGridTextColumn Header="To"
Binding="{Binding To}"
MinWidth="100" />
<DataGridTextColumn Header="Elapsed Time"/>
<DataGridTextColumn Header="HDDC Codes"
Binding="{Binding HDDCCode}"
MinWidth="250" />
<DataGridTextColumn Header="Details of Operations in Sequence and Remarks"
Binding="{Binding Details}"
MinWidth="250" />
<DataGridTextColumn Header="Rot Ftg"
Binding="{Binding RotFtg}" />
<DataGridTextColumn Header="Slide Ftg"
Binding="{Binding SlideFtg}" />
</DataGrid.Columns>
</DataGrid>
And:
<DataGrid AutoGenerateColumns="False"
Name="grid1"
HorizontalAlignment="Center"
FontSize="25"
Margin="10,20,10,40"
CanUserResizeRows="False"
CanUserResizeColumns="False"
CanUserReorderColumns="False"
CanUserAddRows="False"
CanUserDeleteRows="True">
<DataGrid.Columns>
<DataGridTextColumn Header="Product"
Binding="{Binding Product}" />
<DataGridTextColumn Header="Amount"
Binding="{Binding Amount}" />
<DataGridTextColumn Header="Units"
Binding="{Binding Units}" />
</DataGrid.Columns>
</DataGrid>
Now, in the one on the bottom, I can select rows just fine, but the top one, I cannot. I've looked through, and all the properties are the same. I do know at one point, I was able to do so, but now I'm not. Is there a property that I'm missing that I need to set?
I have tried using SelectionMode="Single" SelectionUnit="FullRow", but still nothing.

Template for a datagrid

<DataGrid AutoGenerateColumns="False" Height="200" Margin="0,63,0,0" Name="dataGrid1" MouseDoubleClick="dataGrid1_MouseDoubleClick">
<DataGrid.Columns>
<DataGridTextColumn Header="Hospital Name" Width="100" Binding="{Binding hosp_name}"/>
<DataGridTextColumn Header="Order Number" Width="100" Binding="{Binding ordID}"/>
<DataGridTextColumn Header="Order Date" Width="*" Binding="{Binding placedDate}" />
</DataGrid.Columns>
</DataGrid>
Hey guys, I'm new with wpf, how can I make this into a template so I can render it each time I create a new tab programatically?
Wrap it in a DataTemplate and assign it as ContentTemplate of the TabControl.

Resources