RSS

Maintaining cell state in the Telerik RadGridView for Silverlight

26 Jan

Hi Dear

if you want to click on one empty row cell then enable that row cell button enable then this post help you.

Another help this post you if you want to load save,edit button first load disable if specific column cell empty or value then you apply this code.

 

Design Side Code

Interactivity which is dll

<UserControl x:Class=”SetMyLeads.Silverlight.UI.Controls.CallFowerdGrid”
xmlns:telerik=”http://schemas.telerik.com/2008/xaml/presentation&#8221;
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml&#8221;
xmlns:d=”http://schemas.microsoft.com/expression/blend/2008&#8243;
xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006&#8243;
xmlns:local=”clr-namespace:SetMyLeads.Silverlight.UI”

xmlns:i=”clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity”
mc:Ignorable=”d”>

<Grid x:Name=”LayoutRoot” Background=”White” MinWidth=”800″ MinHeight=”500″ MaxHeight=”500″>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=”*” />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height=”*” />
<RowDefinition Height=”25″></RowDefinition>
</Grid.RowDefinitions>

<telerik:RadGridView x:Name=”rgdCallForwerding” Grid.Row=”0″ Grid.Column=”0″ AutoGenerateColumns=”False”  Style=”{StaticResource DefaultGridStyle}” ScrollViewer.VerticalScrollBarVisibility=”Auto”   RowIndicatorVisibility=”Collapsed” SelectionChanged=”rgdCallForwerding_SelectionChanged” RowEditEnded=”rgdCallForwerding_RowEditEnded” RowLoaded=”rgdCallForwerding_RowLoaded”>
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding=”{Binding CompanyName}” Header=”CompanyName” Width=”auto” IsReadOnly=”True” />
<telerik:GridViewDataColumn DataMemberBinding=”{Binding Number}” Header=”Company Number” Width=”auto” IsReadOnly=”True”/>
<telerik:GridViewDataColumn Header=”FowardNumber”
DataMemberBinding=”{Binding FowardNumber, Mode=TwoWay}” Width=”auto”>
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<TextBlock Text=”{Binding FowardNumber}” />
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
<telerik:GridViewDataColumn.CellEditTemplate>
<DataTemplate>
<TextBox Text=”{Binding FowardNumber, Mode=TwoWay}”  x:Name=”txtFowardNumber” />

</DataTemplate>
</telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>

<telerik:GridViewColumn Width=”100″>
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<telerik:RadButton x:Name=”btnSave”  ToolTipService.ToolTip=”Save Company Fowarding Number” Command=”{Binding FowardNumber}” CommandParameter=”{Binding Number}” Content=”Save”  Click=”btnSave_Click” Style=”{StaticResource DefaultButtonStyle}” Visibility=”Visible”>
</telerik:RadButton>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>

</telerik:RadGridView.Columns>
<i:Interaction.Behaviors>
<local:EmptyDataTemplateBehavior>
<local:EmptyDataTemplateBehavior.EmptyDataTemplate>
<DataTemplate>
<TextBlock Text=”No results found!” Foreground=”red”  HorizontalAlignment=”Center”  VerticalAlignment=”Center” />
</DataTemplate>
</local:EmptyDataTemplateBehavior.EmptyDataTemplate>
</local:EmptyDataTemplateBehavior>
</i:Interaction.Behaviors>
</telerik:RadGridView>
<telerik:RadDataPager Grid.Row=”1″ PageSize=”20″ DisplayMode=”All” AutoEllipsisMode=”Both” NumericButtonCount=”10″ IsTotalItemCountFixed=”True” Source=”{Binding Items, ElementName=rgdCallForwerding}” />
<telerik:RadBusyIndicator Name=”rbiActivity” BusyContent=”Loading data…” />
</Grid>

</UserControl>

 

 

Client Side

Load RadGridView

 

public void bindCallFoward()
{
//this is show busy icon
this.rbiActivity.IsBusy = true;

//we use service to get record you use which way to access data
ServiceManager manager = ServiceManager.GetServiceManager();
SetMyLeadsWebServiceSoapClient ServiceClient = manager.ServiceClient;
ServiceClient.GetCallForwardcompanyNumberCompleted +=new EventHandler<GetCallForwardcompanyNumberCompletedEventArgs>(ServiceClient_GetCallForwardcompanyNumberCompleted);
ServiceClient.GetCallForwardcompanyNumberAsync(CompanyId, manager.User.Login, manager.User.Password);
}

void ServiceClient_GetCallForwardcompanyNumberCompleted(object sender, GetCallForwardcompanyNumberCompletedEventArgs e)
{
if (e.Error == null)
{

if (e.Result != null && e.Result.Count() > 0)
{

rgdCallForwerding.ItemsSource = e.Result;

}
else
{

rgdCallForwerding.ItemsSource = null;
}

this.rbiActivity.IsBusy = false;
}

}

which check if fowerdnumber cell empty then save button show disable

private void rgdCallForwerding_RowLoaded(object sender, RowLoadedEventArgs e)
{
if (e.Row.DataContext != null)
{
callinnumber cbf = e.Row.DataContext as callinnumber;
var button = e.Row.ChildrenOfType<RadButton>().Where(b => b.Name == “btnSave”).FirstOrDefault();

if (cbf.FowardNumber.Length<=0)
{

button.IsEnabled = false;

}
else
{
button.IsEnabled = true;

}

}
}

 

private void rgdCallForwerding_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
{

}

// if you click on empty Call forwerd Cell then enable Save button

I have a RadGridView in which one of the columns contains only buttons.

Depending on the value of a boolean variable linked to a specific record in the grid, I enable or disable the cell containing the button. This is how I achieve this:

private void rgdCallForwerding_SelectionChanged(object sender, SelectionChangeEventArgs e)
{
foreach (callinnumber items in rgdCallForwerding.SelectedItems)
{
//if (rgdCallForwerding.Items.IsEditingItem)
//        {
var    row = this.rgdCallForwerding.ItemContainerGenerator.ContainerFromItem(items) as GridViewRow;

if (row != null)
{

var button = row.FindChildByType<RadButton>();

button.IsEnabled = true;

//var cell = (from c in row.Cells
//            where c.Column.UniqueName == “btnSave”
//         select c).FirstOrDefault();
// if (cell != null)
// {
//     if (items.FowardNumber.Length<=0)
//     {
//         cell.IsEnabled = true;
//     }
//     else
//     {
//         cell.IsEnabled = false;
//     }
// }
}

}

}

 

 

// Save

void btnSave_Click(object sender, RoutedEventArgs e)
{
string _CompanyNumber = “”;
RadButton btnSave = sender as RadButton;
if (btnSave != null)
{

_CompanyNumber = (string)btnSave.CommandParameter;

foreach (callinnumber item in rgdCallForwerding.SelectedItems)
{

Regex regex = new Regex(“^[0-9]*$”);
if (regex.IsMatch(item.FowardNumber))
{
//    if (item.FowardNumber != string.Empty)
//{
if (rgdCallForwerding.Items.IsEditingItem)
{
int _forwardid = item.forwardid;
string _Number = _CompanyNumber;
string _FowardNumber = item.FowardNumber;
int _Companyid = item.Companyid;
ServiceManager manager = ServiceManager.GetServiceManager();
SetMyLeadsWebServiceSoapClient ServiceClient = manager.ServiceClient;
ServiceClient.SaveCallforwardCompleted += new EventHandler<SaveCallforwardCompletedEventArgs>(ServiceClient_SaveCallforwardCompleted);
ServiceClient.SaveCallforwardAsync(_forwardid, _Number, _FowardNumber, _Companyid, manager.User.Login, manager.User.Password);
break;

}

//}
//else
//{
//    MessageBox.Show(“Empty not allowed to Save”);

//}

}
else
{
MessageBox.Show(“Only numbers may be entered here”);

}

}
}

}

private void ServiceClient_SaveCallforwardCompleted(object sender, SaveCallforwardCompletedEventArgs e)
{
if (e.Error == null)
{

MessageBox.Show(“CallFoward Save Successfully.”);

}
bindCallFoward();

}

 

Advertisements
 
Leave a comment

Posted by on January 26, 2012 in Silverlight

 

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: