This is a migrated thread and some comments may be shown as answers.

[Solved] How to disable rows programmtically?

3 Answers 129 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
klogand
Top achievements
Rank 1
klogand asked on 14 Oct 2010, 05:41 PM
I found the IsEnabled property on the GridViewRow, but can't figure out how to change it programmatically. I have a toggleButton in a row. When that is selected, I need to select the current row and disable all other rows and buttons. ISelectable is a simple interface that has an IsSelected boolean property. I can't access the rows from the this.playlistItemsGridView. Any suggestions?

private void ToggleButton_Click(object sender, System.Windows.RoutedEventArgs e)
{
// can only select one at time
// set all isSelected to false except this one
// the item must implement ISelectable
var selectedItems = this.playlistItemsGridView.Items.SourceCollection.Cast<ISelectable>().Where(element => element.IsSelected);
if (selectedItems.Count() == 0)
{
selectedItem.IsSelected = true;
this.playlistItemsGridView.SelectedItem = selectedItem;
}
else if ((ISelectable)selectedItems.First() == selectedItem)
{
// if the selectedItem was unchecked, set to false and return
selectedItem.IsSelected = false;
this.playlistItemsGridView.SelectedItem = null;
return;
}
else
{
((ISelectable)selectedItems.First()).IsSelected = false;
selectedItem.IsSelected = true;
this.playlistItemsGridView.SelectedItem = selectedItem;
}
}

3 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 15 Oct 2010, 07:08 AM
Hello,

 If you want to disable only currently visible rows you can use the approach from this demo otherwise you should use RowStyleSelector.

Regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
klogand
Top achievements
Rank 1
answered on 15 Oct 2010, 04:07 PM
The demo code is working for me. One thing to note that if EnableRowVirtualization = True, then the row returned from the GridViewRow row = this.GridView1.ItemContainerGenerator.ContainerFromItem(item) as GridViewRow; may be null when you aren't expecting it.

Is there an event that fires when new rows are being added to memory when scrolling up or down? For now I just turned row virutalization off, since this table shouldn't get too big.
0
Accepted
Vlad
Telerik team
answered on 18 Oct 2010, 07:34 AM
Hi,

 You can use RowLoaded/RowUnloaded events. 

Best wishes,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
klogand
Top achievements
Rank 1
Answers by
Vlad
Telerik team
klogand
Top achievements
Rank 1
Share this question
or