I am creating an application, and in one of the windows to see the records that are in the database, when I click on the navigation buttons I get an error
The error it throws is:
'Object reference not set as an instance of an object.'
jUEGOViewSource was null.
It's the first application I do in WPF, maybe it's something simple but I do not see where it is.
The code is as follows:
public partial class VerJuegos : Window
{
public VerJuegos()
{
InitializeComponent();
}
//Variables para la vizualización de los registros y navegar entre ellos
private GAMERGABDataSet gAMERGABDataSet;
private GAMERGABDataSetTableAdapters.TableAdapterManager GAMERGABDataSetTableAdapterManager;
private System.Windows.Data.CollectionViewSource jUEGOViewSource;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
GAMES.GAMERGABDataSet gAMERGABDataSet = ((GAMERGABDataSet)(this.FindResource("gAMERGABDataSet")));
// Cargar datos en la tabla JUEGO. Puede modificar este código según sea necesario.
GAMES.GAMERGABDataSetTableAdapters.JUEGOTableAdapter gAMERGABDataSetJUEGOTableAdapter = new GAMERGABDataSetTableAdapters.JUEGOTableAdapter();
gAMERGABDataSetJUEGOTableAdapter.Fill(gAMERGABDataSet.JUEGO);
System.Windows.Data.CollectionViewSource jUEGOViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("jUEGOViewSource")));
jUEGOViewSource.View.MoveCurrentToFirst();
}
//Este método hace regresar a la ventana opciones
private void BtnVolver_Click(object sender, RoutedEventArgs e)
{
Opciones opciones = new Opciones();
opciones.Show();
this.Close();
}
//Este método es para navegar entre los juegos
private void BtnAtras_Click_1(object sender, RoutedEventArgs e)
{
if (jUEGOViewSource.View.CurrentPosition > 0)
{
jUEGOViewSource.View.MoveCurrentToPrevious(); //Aqui me genera el error
}
}
//Este método sirve apra nevagar entre los juegos
private void BtnAdelante_Click(object sender, RoutedEventArgs e)
{
if (jUEGOViewSource.View.CurrentPosition < ((CollectionView)jUEGOViewSource.View).Count -1) //Aqui me genera el error
{
jUEGOViewSource.View.MoveCurrentToNext();
}
}
}
}