So I have DataGrid with DataContext set to a DataTable, and is loaded via FillJobsGrid() when Window_Loaded. This works OK, but I wanted to be able to select a specific item when launching via a command line, the args part works without an issue, just 2 args with a switch and a value. The value is the Id of a row in the JobsGrid, what I cant see is how to select this row. before running BackUpSelectedClicked()
For inspiration amongst many other pages I looked here but which ever way I approach this I have never got a datagrid.Items.count. I guess this is about which event to run my code from. 
Before the mod I had:
private void FillJobsGrid()
{
    using (MySqlClientWrapper db = new MySqlClientWrapper(MyConnString))
    {
        string sql = "SELECT * FROM backupjobs";
        SetJobsTable(db.GetDataTable(sql));
        JobsGrid.DataContext = GetJobsTable();
    }
}
The code I was hoping would do the trick was:
if (RunFromCommandLine)
{
    foreach (DataRowView job in JobsGrid.Items)
    {
        if (job != null)
        {
            DataRow jobRow = job.Row;
            long id = Convert.ToInt32(jobRow["Id"]);
            if (Convert.ToInt32(CommandLineJobId) == id)
            {
                JobsGrid.SelectedItem = job;
            }
        }
    }
    BackUpSelectedClicked();
}
I have tried inserting it in FillJobsGrid, and placing it in DataGrid.DataContextChanged, Initialised, Loaded etc. Any help appreciated.
 
    