DevExpress GridControl cell enabling/disabling - grid

I have a grid control where some columns are editable, some are not.
I'd like to have more fine control, so that depending on some other fields of MyData, the corresponding cells will be enabled or not.
<dxg:GridControl ItemsSource="{Binding MyData}" AutoPopulateColumns="True">
<dxg:GridControl.Columns>
<dxg:GridColumn Header="Name" ReadOnly="True"/>
<dxg:GridColumn Header="ID 1" ReadOnly="False"/>
<dxg:GridColumn Header="ID 2" ReadOnly="False"/>
<dxg:GridColumn Header="ID 3" ReadOnly="False"/>
</dxg:GridControl.Columns>
</dxg:GridControl>
Can't find anything on the DevExpress support site yet. Would you please have any idea?
Thank you!

You can accomplish this task via handling the ShowingEditor event. You can set e.Cancel to True if a cell shouldn't be edited:
void TableView_ShowingEditor(object sender, DevExpress.Xpf.Grid.ShowingEditorEventArgs e)
{
if(...)
{
e.Cancel = true;
}
}
You can also accomplish this task via XAML style:
<Style TargetType="dxg:CellContentPresenter" BasedOn="{StaticResource {dxgt:GridRowThemeKey ResourceKey=CellStyle}}">
<Setter Property="IsEnabled" Value="{Binding Path=RowData.Row.SomePropertyRelatedToEnabledState}"/>
</Style>

Related

Xamarin.Forms SwipeView OnClick Event Handler

I'm experimenting with the new SwipeView controls in Xamarin forms 4.4, and have been going through the FavFighters example (Code on Github) and think it's brilliant.
I'm able to add a Swipe right/left gesture as I wanted, but I can't find out how to add an OnClick event to an item in the list, in a Master/Detail type of project. I was hoping to use the swipe left/right actions for shortcuts, but want the user to click on the listed item to drill-into it further.
Is there a way of adding an OnClick (or an onSelected) event to the SwipeView items?
Yes you can definitely go with Xamarin.Forms.Effects which allows you implement different effects with native features.
You can refer this: https://github.com/mrxten/XamEffects it shows how to have tap effect, long tap effect, which will be helpful in your case [you can do that even without installing third party plugin].
Do you want to achieve the result like following GIF.
If you want to add the click event for your SwipeView. you just add the GestureRecognizers in your swipeView like following code.
<SwipeView>
<SwipeView.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
</SwipeView.GestureRecognizers>
<SwipeView.LeftItems>
<SwipeItems>
<SwipeItem Text="Favorite"
BackgroundColor="LightGreen"
Invoked="SwipeItem_Invoked" />
<SwipeItem Text="Delete"
BackgroundColor="LightPink"
Invoked="SwipeItem_Invoked_1" />
</SwipeItems>
</SwipeView.LeftItems>
<!-- Content -->
<Grid HeightRequest="60"
WidthRequest="300"
BackgroundColor="LightGray">
<Label Text="Swipe right"
HorizontalOptions="Center"
VerticalOptions="Center" />
</Grid>
</SwipeView>
In the background code.
private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
{
Navigation.PushModalAsync(new Page1());
}

ComboBox generate ICallbackEventHandler not found

Im using Devexpress ASP.NET AJAX ComboBox and trying to filter the result using callback events. This is the ASP markup for the ComboBox control
<dx:ASPxComboBox runat="server"
EnableViewState="false"
Width="100%" ID="Project"
ValueField="Value" TextField="Text"
CallbackPageSize="10"
EnableCallbackMode="true"
IncrementalFilteringMode="Contains"
OnItemsRequestedByFilterCondition="Project_ItemsRequestedByFilterCondition"
OnCallback="Project_Callback"
DropDownRows="10"
TextFormatString="{0} {1}">
<Columns>
<dx:ListBoxColumn Caption="Projekt" FieldName="Value" Name="value" />
<dx:ListBoxColumn Caption="Kund" FieldName="Text" Name="text" />
</Columns>
</dx:ASPxComboBox>
And here is the code behind
protected void Project_ItemsRequestedByFilterCondition(object source, DevExpress.Web.ListEditItemsRequestedByFilterConditionEventArgs e)
{
var data = handler.GetProjectList(e.Filter);
Project.DataSource = data;
Project.DataBind();
}
protected void Project_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e)
{
}
Every time i try to write in the combobox the page says that the IEventCallBackHandler is not found. Please see the attached image.
I found the problem. The page is inherit our own base class that has a custom implementation of FindControl.

DevXpress grid view: change GridViewCommandColumnCustomButton Image-Url

all.
I have a DevXpress gridview, and each row contains 2 custom image buttons: edit and cancel.
In the grid is a specific column that will determine whether the image buttons get displayed or not. If the column contains a 5, then don't show the buttons. Otherwise always show the buttons.
How can I access the Image-Url property from the code behind or will it have to be through the JavaScript?
Code extract re custom button definition:
<dxwgv:GridViewCommandColumn ButtonType="Image" Caption="Edit" AllowDragDrop="False" >
<CustomButtons>
<dxwgv:GridViewCommandColumnCustomButton ID="EditButton" Text="Click to edit" Image-Url="~/Images/16x16/edit.png" Visibility="AllDataRows" Image-AlternateText="Edit" />
</CustomButtons>
</dxwgv:GridViewCommandColumn>
<dxwgv:GridViewCommandColumn ButtonType="Image" Caption="Cancel" AllowDragDrop="False">
<CustomButtons>
<dxwgv:GridViewCommandColumnCustomButton ID="CancelButton" Text="Click to cancel" Image-Url="~/Images/16x16/delete2.png" Visibility="AllDataRows" Image-AlternateText="Cancel" />
</CustomButtons>
</dxwgv:GridViewCommandColumn>
Any ideas would be appreciated. Really not have much joy with DevXpress.
Thanks!
Here is one possibility:
protected void ASPxGridView1_CustomButtonInitialize(object sender, ASPxGridViewCustomButtonEventArgs e)
{
int i = Convert.ToInt32((sender as ASPxGridView).GetMasterRowKeyValue());
if (i == 5)
e.Image.Url = "images/checkmark.gif";
else
e.Image.Url = "images/trash.gif";
}
Then of course in the ASPX file you would need to add:
oncustombuttoninitialize="ASPxGridView1_CustomButtonInitialize"

silverlight datagrid multicontrol TemplateColumn TabIndex issue

In SL4 DataGrid I have the following multicontrol column:
<sdk:DataGridTemplateColumn Header="Address Line1
Address Line 2" MinWidth="200">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=Address1}"/>
<TextBlock Text="{Binding Path=Address2}"/>
</StackPanel>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
<sdk:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<StackPanel>
<TextBox Background="Transparent" BorderThickness="0"
TabIndex="0"
Text="{Binding Path=Address1, Mode=TwoWay}"/>
<TextBox Background="Transparent" BorderThickness="0"
TabIndex="1"
Text="{Binding Path=Address2, Mode=TwoWay}"/>
</StackPanel>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellEditingTemplate>
</sdk:DataGridTemplateColumn>
In edit mode pressing Tab key while at address1 moves focus to next DataGrid column but not to address2 textbox. If I delete CellTemplate and CellEditingTemplate to be CellTemplate instead, then TabIndex works as expected, however, current column stay the same, so if datagrid has many columns, some of which are hidden, then auto scrolling doesn't occur. What should I do to solve this problem?
A little bit late, but i found a workaround for this problem.
Just add a KeyDown EventHandler to your CustomControl:
private void address1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key.Equals(Key.Tab) && address2.IsEnabled)
{
address2.Focus();
e.Handled = true;
}
}
Probably, having multiple controls inside datagrid cell is bad idea. If multiple controls needs to be inside cell, then better way seems to be to create custom composite control and place it inside cell.

how to capture the "Menu Item 1" text in the dropdown button and assign to textbox

I am using a code snippet from codeproject of dropdown button.
< m:SplitButton Content="TWB" Name="btnSearch"
Grid.Row="0" Grid.Column="0"
Style="{StaticResource aeroNormalColorSplitButtonStyle}"
Click="btnSearch_Click"
Width="60" Height="30"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Mode="{Binding ElementName=modeSelector, Path=SelectedItem}"
Placement="{Binding ElementName=placementSelector, Path=SelectedItem}" MouseLeftButtonDown="btnSearch_MouseLeftButtonDown"
MenuItem Header="TWB"/>
MenuItem Header="PWB">
/MenuItem>
</m:SplitButton>
so, beside this splitdown button, I have a textbox(which is basically a search box). So, as the above code snippet shows the 2 menu items as "TWB" and "PWB", I have to fill the textbox when TWB is selected from the dropdown button and also the same text should be displayed on the button too (TWB).
if i click PWB from the dropdownbutton, I should get the "PWB" name on the button and the same PWB name should be displayed in the textbox too.
Please help me.
Thank You,
Ramm
I tried by adding ListBox to the SplitButton, Now I am able to see the text in the textbox.
Modified the above Xaml code to
<m:SplitButton Content="TWB" Name="btnSearch"
Grid.Row="0" Grid.Column="0"
Style="{StaticResource aeroNormalColorSplitButtonStyle}"
Click="btnSearch_Click"
Width="60" Height="30"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Mode="{Binding ElementName=modeSelector, Path=SelectedItem}"
Placement="{Binding ElementName=placementSelector, Path=SelectedItem}">
<ListBox x:Name="TransitionKind" SelectionChanged="TransitionKind_SelectionChanged">
<ListBoxItem Content="TWB"/>
<ListBoxItem Content="PWB"/>
</ListBox>
</m:SplitButton>
in the code behind,
btnSearch.Click += new RoutedEventHandler(btnSearch_Click);
TransitionKind.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(TransitionKind_SelectionChanged);
private void TransitionKind_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
btnSearch.Content = ((ListBoxItem)TransitionKind.SelectedItem).Content;
txtBxSearch.Text = "Search " + (string) btnSearch.Content;
}
Now, I am able to see the text in the textbox changing to the click of dropdown button.
Thank you,
Ramm

Resources