The code is supposed to trigger once I'm done editing data in the secondary window. Everything works as it should, but the ScrollIntoView
won't trigger. It selects the correct Index
, but then refuses to scroll to it.
I'm completely lost at this point. I'm suspecting it has to do something with the fact that it takes about 500ms to load the DataTable
in the DataGrid
(I'm playing with some weird queries) and the code tries to move to the SelectedIndex
before it is even possible?
Note: "dg_part.SelectedIndex = -1;" has to be there, or I can't trigger a new SelectionChanged event correctly.
Code:
public void DG_Part_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (CurrentPartID != 0)
{
int lastId = CurrentPartID;
EditWindow ew = new EditWindow(CurrentPartID)
{
Owner = this
};
ew.ShowDialog();
if (Public_Strings.invokeDataGridParts == "yes")
{
InvokeDataGridPart();
SqlPartsSetToRow(lastId);
dg_part.ScrollIntoView(dg_part.Items[dg_part.SelectedIndex]);
dg_part.SelectedIndex = -1;
}
}
}
public void InvokeDataGridPart()
{
SqlCommand cmd = new SqlCommand
{
CommandText = "SELECT * FROM cbu_deli WHERE [IDX] = '" + CurrentID + "' ORDER BY LEN ([DEL]), [DEL] ASC, [OPIS] DESC, [DELEZ] DESC",
Connection = con
};
Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
SqlDataAdapter da = new SqlDataAdapter(cmd);
dtPart.Clear();
da.Fill(dtPart);
dg_part.ItemsSource = dtPart.DefaultView;
mycollection.GroupDescriptions.Clear();
mycollection.GroupDescriptions.Add(new PropertyGroupDescription("DEL"));
dg_part.ItemsSource = mycollection.View;
Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow;
}
public int CurrentPartID
{
get
{
int tmp = 0;
if (dg_part.SelectedIndex >= 0)
{
int.TryParse(dtPart.Rows[dg_part.SelectedIndex].ItemArray[0].ToString(), out tmp);
}
return tmp;
}
}
public void SqlPartsSetToRow(int Id)
{
Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
dg_part.SelectionChanged -= DG_Part_SelectionChanged;
while (CurrentPartID != Id && dg_part.SelectedIndex < dtPart.Rows.Count - 1)
{
dg_part.SelectedIndex++;
}
dg_part.SelectionChanged += DG_Part_SelectionChanged;
Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow;
}