Skip to main content
Home Forums Silverlight Programming WCF RIA Services Dynamically enable/disable editing in datagrid
12 replies. Latest Post by Jonathan Shen – MSFT on November 9, 2009.
(0)
pratixa
Member
264 points
88 Posts
11-02-2009 6:22 AM |
Hello all,
I want to disable editing in datagrid runtime......say at datagrid loading row event......... user can not able to edit in the datagrid by double clicking the row of the datagrid........ how can i achieve this...Any help would be highly appreciated......
Ardman
Contributor
3320 points
919 Posts
11-02-2009 6:34 AM |
You could set the IsReadOnly to true in order to stop the editing.
11-02-2009 6:42 AM |
Hi Ardman,
Thanx for reply..
In which event and which elemwnt's read only property i can change.......if possible then provide the source code...............
ken tucker
All-Star
16276 points
2,479 Posts
11-02-2009 6:50 AM |
In the DataGrid PreparingCellForEdit event cast the EditElement to a textbox and set it IsReadOnly to true when you do not want the user to be able to edit the cell
http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.preparingcellforedit(VS.95).aspx
Private Sub dgProducts_PreparingCellForEdit(ByVal sender As Object, ByVal e As System.Windows.Controls.DataGridPreparingCellForEditEventArgs) Handles dgProducts.PreparingCellForEdit If DirectCast(dgProducts.SelectedItem, Northwind.Products).ProductName.StartsWith("C") Then DirectCast(e.EditingElement, TextBox).IsReadOnly = True End If End Sub
11-02-2009 7:56 AM |
Hi Ken tucker,
Actually i have the combobox in the editing..........i just give u my design code...............
<data:DataGridTemplateColumn.CellTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Stretch"> <TextBlock x:Name="txtFinRespCode" Text="" Margin="3,0,0,0" /> <TextBlock x:Name="txtFinRespLvl" Text="" Margin="10,0,0,0" /> </StackPanel> </DataTemplate> </data:DataGridTemplateColumn.CellTemplate> <data:DataGridTemplateColumn.CellEditingTemplate> <DataTemplate> <ComboBox x:Name="cbFinancialResLvl" Width="200" Height="30" VerticalAlignment="Top" HorizontalAlignment="Left" ItemsSource="{Binding FRL,Source={StaticResource cFRL}}" SelectionChanged="cbFinancialResLvl_SelectionChanged"> <ComboBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock x:Name="txtFinRespCode" Text="{Binding auto_id,Mode=TwoWay}"/> <TextBlock x:Name="txtFinRespLvl" Text="{Binding mfrl_desc,Mode=TwoWay}" Margin="10,0,0,0" /> </StackPanel> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> </DataTemplate> </data:DataGridTemplateColumn.CellEditingTemplate>
11-02-2009 7:59 AM |
Hi,
So, i m getting the comboBox as the EdititngElement.........................but does not want to allow the user to double click the cell and go in to edit mode................
11-02-2009 8:02 AM |
Is it not just worth assigning the IsReadOnly property to true in your XAML on the columns that you don't want users to edit?
11-02-2009 8:05 AM |
Hi ardman,
That is y i have not set the IsReadOnly propertyin XAML............i want to set it run time..dynamically......
Jonathan...
24939 points
2,425 Posts
11-06-2009 4:54 AM |
Hi Pratixa,
Another direct way is to detect the ComboBox's Loaded event and set its IsEnabled/IsHitTestVisible property.
Best regards,
Jonathan
sasideva
240 points
58 Posts
11-06-2009 6:37 AM |
hi,
Datagrid loading row you can give like this. in loading row you have to enable/disable control .
{
Chk_Status.IsEnabled =
11-06-2009 10:59 PM |
Hi sasideva,
Thanks for the reply...My combobox is in the celleditTemplate, so i can not find the combo box in the loading_row event....
11-06-2009 11:06 PM |
Hi, jonathan,
Thanks for reply..There is no any property like IsReadOnly of the combo box...i have generated the loded event of the combo box in the datagrid's preparecellforedit event.but i m not able find the combo box's IsReadOnly property.
11-09-2009 1:16 AM |
Several alternative ways here. We can set its IsEnabled or IsHitTestVisible property or detect its SelectionChanged event and change back its original value.