Hello,
I trying to move rows up or down depending on user selection from the Context Menu.
And for some reason (still trying to figure out), the IndexOf is returning -1.
Below are my XAML code =>
<telerik:RadGridView x:Name="gridView1" Grid.Row ="1" AutoGenerateColumns="False" Margin="0,5,0,10" FontSize="12" Deleted="OnDeletedIO"
Deleting="OnDeletingIO" telerik:StyleManager.Theme="Summer" DataGridCell.GotFocus="DataGrid_CellGotFocus">
<telerik:RadGridView.ContextMenu>
<ContextMenu >
<MenuItem Header="MoveUp" Click="MoveUp_click"/>
</ContextMenu>
</telerik:RadGridView.ContextMenu>
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding name}" Header="Name" IsReadOnly="False"/>
<telerik:GridViewComboBoxColumn x:Name="ComboGroup" DataMemberBinding="{Binding group}" Header="Group"/>
<telerik:GridViewComboBoxColumn x:Name="ComboRTU" DataMemberBinding="{Binding rtu}" Header="RTUs"/>
<telerik:GridViewComboBoxColumn x:Name="ComboOP" DataMemberBinding="{Binding op}" Header="Operation"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding addr}" Header="Address"/>
<telerik:GridViewComboBoxColumn x:Name="ComboTypes2" DataMemberBinding="{Binding dataType}" Header="Data Type"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding swapByte}" Header="Byte
Swapping"
IsReadOnly="True">
</telerik:GridViewDataColumn>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
C# code =>
namespace MBM_WPF
{
public partial class MainWindow : Window
{
MBM mbm1 ;
MBM_view mbmView;
public MainWindow(string path)
{
StyleManager.ApplicationTheme = new SummerTheme();
InitializeComponent();
logger = LogManager.GetLogger("Instruct.MBM_Main");
Configpath = path;
//Populating ItemsSource here
catch
{
mbm1 = new MBM();
mbmView = new MBM_view(mbm1, OnSettingChanged);
BindMyData();
}
}
private void MoveUp_click(object sender, RoutedEventArgs e)
{
//Get the clicked MenuItem
var menuItem = (MenuItem)sender;
//Get the ContextMenu to which the menuItem belongs
var contextMenu = (ContextMenu)menuItem.Parent;
//Find the placementTarget
var item = (RadGridView)contextMenu.PlacementTarget;
int index = this.gridView1.Items.IndexOf(item.SelectedItem);
this.gridView1.Items.Remove(item.SelectedItem);
this.gridView1.Items.Insert(index - 1, item.SelectedItem);
item.SelectedItem = item;
mbmView.IoListCleanUp();
mbmView.AlarmsCleanUp();
}
}
}
Please help.
Thank you!!
Regards,
Darren