Rad grid localization - visual-studio-2010

How do i localize the text that is written in the bottom when pagination is done in the radgrid. For Example text which displays the page number Page No. 1 2 3

I'm not sure in which context you use the RagGrid, but there is how I changed the pager strings for RagGrid in my ASP.NET project:
protected override void OnItemDataBound(GridItemEventArgs e)
{
// Localize pager.
if (e.Item is GridPagerItem)
{
var pager = (GridPagerItem)e.Item;
var label = pager.FindControl("GoToPageLabel") as Label;
if (label != null)
label.Text = "Page #:";
label = pager.FindControl("PageOfLabel") as Label;
if (label != null)
label.Text = string.Format(", total: {0}", label.Text.Substring(label.Text.IndexOf(' ')));
label = pager.FindControl("ChangePageSizeLabel") as Label;
if (label != null)
label.Text = "Items per page:";
var button = pager.FindControl("GoToPageLinkButton") as Button;
if (button != null)
button.Text = "Go to this page";
button = pager.FindControl("ChangePageSizeLinkButton") as Button;
if (button != null)
button.Text = "Change page size";
return;
}
base.OnItemDataBound(e);
}
I assuming that there is almost same way to do it for WinForms. Also you can subscribe to ItemDataBound event instead of overriding the protected method.

There are RadControls for various presentation frameworks, you should be more specific.
If you're using AJAX ASP.NET, it should be something along PagerTooltipFormatString in RadGrid.PagerStyle (see here).

Related

Xamarin - How to know what has been clicked in collection view?

I have a CollectionView with an image and a button in it. I use following code to see if somebody pressed anywhere within the cell:
private void CollectionView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (((CollectionView)sender).SelectedItem != null)
{
var item = (picdata)e.CurrentSelection.FirstOrDefault();
((CollectionView)sender).SelectedItem = null;
if (allowfullscreen == "1" || allowfullscreen == "true")
{
Navigation.PushAsync(new Picture());
}
}
}
But how can I know if he clicked the button inside the cell? I was trying to do it via the Click event, but then I do not know which one of all the buttons has been clicked.
you can get the item from the BindingContext of the sender
var item = (picdata)(Button)sender.BindingContext;

Xamarin.Android: Click event on Textview inside list view cell called multiple times

I have a list view in which inside each cell I have two textview, I need to handle the click event for one of the textview element. But when I put the click event inside the GetView() of the adapter, it is called multiple times.
public override View GetView(int position, View convertView, ViewGroup parent)
{
var item = tableItems[position];
ViewHolder holder;
View view = convertView;
if (view == null)
{
LayoutInflater layoutInflator = LayoutInflater.From(mContext);
view = layoutInflator.Inflate(Resource.Layout.myListViewCell, null);
holder = new ViewHolder();
holder.tvEmpName = view.FindViewById<TextView>(Resource.Id.tv_EmpName);
holder.tvEmpPhone = view.FindViewById<TextView>(Resource.Id.tv_EmpPhone);
view.Tag = holder;
}
else
{
holder = (ViewHolder)view.Tag;
}
holder.tvEmpName.Text = item.FullName;
holder.tvEmpPhone.Text = item.Phone;
holder.tvEmpPhone.Click += (sender, e) => {
// Click event to launch the Popup menu
// This event is being called multiple times, as Get view() being called multiple times.
};
return view;
}
I gone through this similar thread, but didn't find any solution.
The event is called multiple times because evertime when the metod getview is called you add a click event with +=.
In this case you can put the click event inside the if, like that:
if (view == null)
{
LayoutInflater layoutInflator = LayoutInflater.From(mContext);
view = layoutInflator.Inflate(Resource.Layout.myListViewCell, null);
holder = new ViewHolder();
holder.tvEmpName = view.FindViewById<TextView>(Resource.Id.tv_EmpName);
holder.tvEmpPhone = view.FindViewById<TextView>(Resource.Id.tv_EmpPhone);
view.Tag = holder;
holder.tvEmpPhone.Click += (sender, e) => {
// Code here
};
}
But the recyclerview is better than listview for this.

One button selected at a time in listbox (background color)

So I want to set the currently selected button to green background in a listbox while all buttons that are not selected should stay black. How can I do this. View examplecode below.. cant get it working though.
foreach(Button btn in ListBox.Items)
btn.Background = new SolidColorBrush(Colors.Black);
Button clickedButton = sender as Button;
clickedButton.Background = new SolidColorBrush(Colors.Green);
If you want it that way (without Binding and converters) here you go:
(I'm also assuming that only a button is in the listbox item)
for (int i = 0; i < ListBox.Items.Count; i++)
{
Button currentButton = ListBox.Items[i] as Button;
if(currentButton != null)
{
if (i == ListBox.SelectedIndex)
currentButton.Background = new SolidColorBrush(Colors.Green);
else
currentButton.Background = new SolidColorBrush(Colors.Black);
}
}

windows phone listbox

1) This is my code for listbox2 selectionchanged
void PrintText2(object sender, SelectionChangedEventArgs args)
{
if (null != listBox2.SelectedItem)
{
ListBoxItem lbi = ((sender as ListBox).SelectedItem as ListBoxItem);
textBlock4.Text = lbi.Content.ToString();
}
}
2) This my code for listbox1 selecionchanged
void PrintText1(object sender, SelectionChangedEventArgs args)
{
if (null != listBox1.SelectedItem)
{
ListBoxItem l = ((sender as ListBox).SelectedItem as ListBoxItem);
textBlock6.Text = l.Content.ToString();
if (textBlock6.Text == "Angle")
{
loadlistAngle();
}
}
}
3)
void loadlistAngle()
{
listBox2.Items.Clear();
listBox2.Items.Add("Radian");
listBox2.Items.Add("Degree");
}
4) listbox1 contains static item "Angle" and on selection of "Angle" at runtime,Angle gets loaded in textBolck6 and then new items "radian" and " degree" gets added to listbox2
5) after this when I click "radian" of listbox2 ,the "radian value doesn't get loaded into textblock4 ,it gives "NullReferenceException" in "lbi.Content.ToString()"
6) how do I modify my code so that at runtime "radian" value get loaded in textblock4 and new items generated will get selected in listbox2
Run your code in the debugger after adjusting it the following way:
Where you have textBlock4.Text = lbi.Content.ToString(); replace it with:
object lbiContent = lbi.Content;
if(lbiContent != null) textBlock4.Text = lbiContent.ToString();
Put a break point at the object line. This way you will know what exactly is the contents of your listboxitem, and if it is null.
Most likely you are just placing something wrong in
listBox2.Items.Clear();
listBox2.Items.Add("Radian");
listBox2.Items.Add("Degree");
Other then that, everything is correct in the code you have provided.
Update:
Also, try substituting
ListBoxItem lbi = ((sender as ListBox).SelectedItem as ListBoxItem);
with
ListBoxItem lbi = ((sender as ListBox).SelectedItem;
You don't need to do a double cast.
And the Selected item of the list box may still be empty.
Update 2:
Most likely this shoud be how you retrieve the selected item:
ListBoxItem lbi = (args.AddedItems[0] as ListBoxItem);

WP7 Get listbox item text

Is there a way to get the text of a clicked listbox item?
So on click it sets a string to the text in the list box item.
In a new DataBound App, changed the following method to see 3 ways of getting this:
// Handle selection changed on ListBox
private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// If selected index is -1 (no selection) do nothing
if (MainListBox.SelectedIndex == -1)
return;
var string1 = ((sender as ListBox).SelectedItem as ItemViewModel).LineOne;
var string2 = (MainListBox.SelectedItem as ItemViewModel).LineOne;
var string3 = (e.AddedItems[0] as ItemViewModel).LineOne;
// Navigate to the new page
NavigationService.Navigate(new Uri("/DetailsPage.xaml?selectedItem=" + MainListBox.SelectedIndex, UriKind.Relative));
// Reset selected index to -1 (no selection)
MainListBox.SelectedIndex = -1;
}

Resources