<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.
Related
.. 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>
<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>
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>
<DataGrid Width="auto" AutoGenerateColumns="False" Name="dgData" >
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding HODAppID}" Width="75" Header="HOD APPID" />
<DataGridTextColumn Binding="{Binding Req}" Header="CandidateID" Visibility="Hidden" />
<DataGridTextColumn Binding="{Binding Req}" Header="RequisitionNo" Visibility="Hidden" />
<DataGridTextColumn Binding="{Binding Candidate}" Width="1.3*" Header="CANDIDATE NAME" />
<DataGridTextColumn Binding="{Binding Req}" Width="*" MinWidth="200" Header="REQUIREMENT"/>
<DataGridTextColumn Binding="{Binding status}" Width="80" Header="Status" />
<DataGridTextColumn Binding="{Binding daysopen}" Width="120" x:Name="noDays" Header="# of Days Open" />
hi i have a datagrid , something like above, i was trying to get cell value in column noDays, and change the fore color based on the value in it.please help in this regard.Thanks in advance
Create a converter using IValueConverter and add it to your noDays column Foreground property. The converter should return a brush value based on the value of the daysopen property.
http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx
EDIT:
Apparently IValueConverter doesn't work straight on DataGridTextColumn. More info and an example can be found at http://social.msdn.microsoft.com/Forums/en/wpf/thread/77a9f317-d0be-4aed-9dc9-9917ad98ffc8.
I currently have a Combo box that has data that is bind from a database:
<ComboBox x:Name="bookingComboBox"
ItemsSource="{Binding ElementName=bookingDomainDataSource, Path=Data}"
Height="20"
VerticalAlignment="Top"
Margin="387,79,114,0">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Width="150"
Text="{Binding Path=bookingName}" />
<TextBlock Text="{Binding Path=bookingDate, StringFormat=d MMMM yyyy}"
Width="100" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
I also have the datagrid:
<sdk:DataGrid AutoGenerateColumns="False"
Height="200"
HorizontalAlignment="Left"
ItemsSource="{Binding Data, ElementName=bookingDomainDataSource}"
Margin="147,132,0,0"
x:Name="bookingDataGrid"
RowDetailsVisibilityMode="VisibleWhenSelected"
VerticalAlignment="Top"
Width="400">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn x:Name="bookingIdColumn"
Binding="{Binding bookingId, Mode=OneWay}"
Header="Booking Id"
IsReadOnly="True"
Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="bookingNameColumn"
Binding="{Binding bookingName}"
Header="Booking Name"
Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="bookingDateColumn"
Binding="{Binding bookingDate}"
Header="Booking Date"
Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="paymentIdColumn"
Binding="{Binding paymentId}"
Header="Payment Id"
Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="showIdColumn"
Binding="{Binding showId}"
Header="Show Id"
Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="ticketIdColumn"
Binding="{Binding ticketId}"
Header="Ticket Id"
Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="ticketQuantityColumn"
Binding="{Binding ticketQuantity}"
Header="Ticket Quantity"
Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="userIdColumn"
Binding="{Binding userId}"
Header="User Id"
Width="SizeToHeader" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
I would like the data grid to change to the row of the row set from the combobox.
How can I do this?
Thanks
If all controls are bound to the same source you should be able to use the following property:
IsSynchronizedWithCurrentItem="True"
Which should be set on both the ComboBox and the DataGrid.
The ItemsSource property must be set to a collection (IEnumerable). What would it mean to set the ItemsSource to a non-collection object? It wouldn't be a "source" of items.
The easiest way to do what you're asking for would be to bind the data grid's ItemsSource to the ComboBox's SelectedItem property. If you want the grid to show child data of the selected item in the combo box, try something like ItemsSource="{Binding ElementName=bookingComboBox, Path=SelectedItem.CHILD_DATA_PROPERTY}".