This program hangs when trying to generate fixtures when the table is empty:

using System;
using Gtk;
using Mono.Data.Sqlite;
using System.IO;

public partial class MainWindow: Gtk.Window
{	
	//SQLite variables
	static SqliteConnection DataConn;
    static SqliteCommand DataComm = new SqliteCommand();
    static SqliteDataReader DataReader;	
	string dsn;
	
	//tree_1 variables
	Gtk.TreeViewColumn name_1 = new Gtk.TreeViewColumn ();
	Gtk.ListStore List_1 = new Gtk.ListStore (typeof (string));
	Gtk.CellRendererText NameCell_1 = new Gtk.CellRendererText ();
	
	//tree_2 variables
	Gtk.TreeViewColumn home_team_2 = new Gtk.TreeViewColumn ();
	Gtk.TreeViewColumn away_team_2 = new Gtk.TreeViewColumn ();
	Gtk.TreeStore List_2 = new Gtk.TreeStore (typeof (string), typeof (string));
	Gtk.CellRendererText homeCell_2 = new Gtk.CellRendererText ();	
	Gtk.CellRendererText awayCell_2 = new Gtk.CellRendererText ();
	
	//Any
	Gtk.TreeIter iter;
	
	int numofteams;
	string[] teamsa;
	string[] homea;
	string[] awaya;
	int[,] fixturea;
	
	public void generate_fixtures()
	{
		Random rand = new Random();
		int home;
		int away;
		int numoffix = numofteams/2;
		int j = 0;
		homea = new string[numoffix];
		awaya = new string[numoffix];
		int[] teamsused = new int[numofteams];
		for (int i = 0; i < numoffix; i++){
			do{
				home = rand.Next(0, numofteams);
				away = rand.Next(0, numofteams);
			} while (home == away || fixturea[home,away] != 0 || teamsused[home] != 0 || teamsused[away] != 0);
			fixturea[home,away] = 1;
			homea[j] = teamsa[home];
			awaya[j] = teamsa[away];
			teamsused[home] = 1;
			teamsused[away] = 1;
			j++;
		}
	}
	
	public void generate_all_fixtures()
	{
		fixturea = new int[numofteams,numofteams];
		DataComm.CommandText = "DELETE FROM fixture;";
		DataComm.ExecuteNonQuery();	
		int blah = (numofteams-1) * 2;
		for (int i = 0; i <= blah; i++){
			generate_fixtures();
			for (int j = 0; j < numofteams/2; j++){
				DataComm.CommandText = string.Format("INSERT INTO fixture VALUES (null, \"{0}\", \"{1}\", {2});", homea[j], awaya[j], i+1);
				DataComm.ExecuteNonQuery();				
			}
		}
		tree_2_add_data();
	}	
	
	public void generate_team_array()
	{
		DataComm.CommandText = "SELECT * FROM teams;";
		DataReader = DataComm.ExecuteReader();
		teamsa = new string[numofteams];
		int i = 0;
		string returned;
		while (DataReader.Read()){
			returned = DataReader["Name"].ToString();
			teamsa[i] = returned;
			i++;
		}	
		DataReader.Close();
	}
	
	public void tree_1_add_data()
	{
		numofteams = 0;
		DataComm.CommandText = "SELECT * FROM teams;";
		DataReader = DataComm.ExecuteReader();
		string returned;
		while (DataReader.Read()){
			returned = DataReader["Name"].ToString();
			List_1.AppendValues(returned);
			numofteams += 1;
		}
		DataReader.Close();
		generate_team_array();
	}
	
	public void tree_2_add_data()
	{
		string day;
		List_2.Clear();
		for (int i = 0; i < numofteams/2; i++){
			DataComm.CommandText = string.Format("SELECT * FROM fixture where Day = {0};", i+1);
			DataReader = DataComm.ExecuteReader();
			if (DataReader.HasRows){
				day = string.Format("Day {0}", i+1);
				iter = List_2.AppendValues(day);
			}
			while (DataReader.Read()){
				List_2.AppendValues(iter, DataReader["Home"].ToString(), DataReader["Away"].ToString());
				numofteams += 1;
			}
			DataReader.Close();	
		}
	}
	
	public void tree_conf()
	{
		//tree_1
		name_1.Title = "Name"; 
		tree_1.AppendColumn(name_1);
		tree_1.Model = List_1;
		name_1.PackStart (NameCell_1, true);
		name_1.AddAttribute (NameCell_1, "text", 0);
		tree_1_add_data();
		
		//tree_2
		home_team_2.Title = "Home Team";
		away_team_2.Title = "Away Team";
		tree_2.AppendColumn(home_team_2);
		tree_2.AppendColumn(away_team_2);
		tree_2.Model = List_2;
		home_team_2.PackStart(homeCell_2, true);
		home_team_2.AddAttribute(homeCell_2, "text", 0);
		away_team_2.PackStart(awayCell_2, true);
		away_team_2.AddAttribute(awayCell_2, "text", 1);
		tree_2_add_data();
	}	
	
	public MainWindow (): base (Gtk.WindowType.Toplevel)
	{
		Build ();
		bool first = false;
		if (!File.Exists("league.db")){
			SqliteConnection.CreateFile("league.db");
			first = true;
		}
		string dsn = "Data Source=league.db;";
		DataConn = new SqliteConnection(dsn);
		DataConn.Open();
		DataComm.Connection = DataConn;
		if (first){
			DataComm.CommandText = "CREATE TABLE teams (ID INTEGER PRIMARY KEY, Name TEXT);";
			DataComm.ExecuteNonQuery();	
			DataComm.CommandText = "CREATE TABLE fixture (ID INTEGER PRIMARY KEY, Home TEXT, Away TEXT, Day INTEGER);";
			DataComm.ExecuteNonQuery();				
		}
		tree_conf();
	}
	
	protected void OnDeleteEvent (object sender, DeleteEventArgs a)
	{
		Application.Quit ();
		a.RetVal = true;
	}

	protected virtual void on_submit_1 (object sender, System.EventArgs e)
	{
		//if it's empty don't do anything
		string team = team_1.Text;
		if (team == ""){
			return;
		}
		//Insert data into the table
		DataComm.CommandText = string.Format("INSERT INTO teams VALUES (null, \"{0}\");", team);
		DataComm.ExecuteNonQuery();
		//Clear tree_1
		List_1.Clear();
		//Query database for teams
		tree_1_add_data();
	}

	protected virtual void on_generate_2 (object sender, System.EventArgs e)
	{
		generate_all_fixtures();
	}
}

& when you try to generate fixtures when the table is full it gives a Index Error at 51:

homea[j] = teamsa[home];

why?

This is the second time I've seen this project, which I cannot do anything with because I don't have your 3rd party libraries or data. I've noticed you made a few modifications since the previous thread.

Anyway, these lines look a little suspicious, and "blah" is probably not the best name you could have come up with...

int blah = (numofteams-1) * 2;
		for (int i = 0; i <= blah; i++)

I'm wondering whether you meant for "blah" to be = numofteams * 2 - 1 and for condition to be i < blah ?

Is this an application that is available for free that you are modifying that we can download the original somewhere and get the 3rd party libraries installed?

I've stopped the freezing, but not the index error

using System;
using Gtk;
using Mono.Data.Sqlite;
using System.IO;

public partial class MainWindow: Gtk.Window
{	
	//SQLite variables
	static SqliteConnection DataConn;
    static SqliteCommand DataComm = new SqliteCommand();
    static SqliteDataReader DataReader;	
	string dsn;
	
	//tree_1 variables
	Gtk.TreeViewColumn name_1 = new Gtk.TreeViewColumn ();
	Gtk.ListStore List_1 = new Gtk.ListStore (typeof (string));
	Gtk.CellRendererText NameCell_1 = new Gtk.CellRendererText ();
	
	//tree_2 variables
	Gtk.TreeViewColumn home_team_2 = new Gtk.TreeViewColumn ();
	Gtk.TreeViewColumn away_team_2 = new Gtk.TreeViewColumn ();
	Gtk.TreeStore List_2 = new Gtk.TreeStore (typeof (string), typeof (string));
	Gtk.CellRendererText homeCell_2 = new Gtk.CellRendererText ();	
	Gtk.CellRendererText awayCell_2 = new Gtk.CellRendererText ();
	
	//Any
	Gtk.TreeIter iter;
	
	int numofteams;
	int numofteamsOLD;
	string[] teamsa;
	string[] homea;
	string[] awaya;
	int[,] fixturea;
	
	public void generate_fixtures()
	{
		Random rand = new Random();
		int home;
		int away;
		int numoffix = numofteams/2;
		Console.WriteLine("numofteams: {0}", numofteams);
		Console.WriteLine("numoffix  : {0}", numoffix);
		int j = 0;
		homea = new string[numoffix];
		awaya = new string[numoffix];
		int[] teamsused = new int[numofteams];
		int k = 0;
		for (int i = 0; i < numoffix; i++){
			do{
				home = rand.Next(0, numofteams);
				away = rand.Next(0, numofteams);
				k++;
			} while (home == away || fixturea[home,away] != 0 || teamsused[home] != 0 || teamsused[away] != 0);
			fixturea[home,away] = 1;
			Console.WriteLine(j);
			homea[j] = teamsa[home];
			awaya[j] = teamsa[away];
			teamsused[home] = 1;
			teamsused[away] = 1;
			j++;
		}
	}
	
	public void generate_all_fixtures()
	{
		fixturea = new int[numofteams,numofteams];
		DataComm.CommandText = "DELETE FROM fixture;";
		DataComm.ExecuteNonQuery();	
		int blah = (numofteams-1) * 2;
		for (int i = 0; i < blah; i++){
			generate_fixtures();
			for (int j = 0; j < numofteams/2; j++){
				DataComm.CommandText = string.Format("INSERT INTO fixture VALUES (null, \"{0}\", \"{1}\", {2});", homea[j], awaya[j], i+1);
				DataComm.ExecuteNonQuery();		
			}
		}
		tree_2_add_data();
	}	
	
	public void generate_team_array()
	{
		DataComm.CommandText = "SELECT * FROM teams;";
		DataReader = DataComm.ExecuteReader();
		teamsa = new string[numofteams];
		int i = 0;
		string returned;
		while (DataReader.Read()){
			returned = DataReader["Name"].ToString();
			teamsa[i] = returned;
			i++;
		}	
		DataReader.Close();
	}
	
	public void tree_1_add_data()
	{
		numofteams = 0;
		DataComm.CommandText = "SELECT * FROM teams;";
		DataReader = DataComm.ExecuteReader();
		string returned;
		while (DataReader.Read()){
			returned = DataReader["Name"].ToString();
			List_1.AppendValues(returned);
			numofteams += 1;
		}
		DataReader.Close();
		generate_team_array();
	}
	
	public void tree_2_add_data()
	{
		string day;
		List_2.Clear();
		for (int i = 0; i < numofteams/2; i++){
			DataComm.CommandText = string.Format("SELECT * FROM fixture where Day = {0};", i+1);
			DataReader = DataComm.ExecuteReader();
			if (DataReader.HasRows){
				day = string.Format("Day {0}", i+1);
				iter = List_2.AppendValues(day);
			} else {
				DataReader.Close();
				return;
			}
			while (DataReader.Read()){
				List_2.AppendValues(iter, DataReader["Home"].ToString(), DataReader["Away"].ToString());
				numofteams += 1;
			}
			DataReader.Close();	
		}
	}
	
	public void tree_conf()
	{
		//tree_1
		name_1.Title = "Name"; 
		tree_1.AppendColumn(name_1);
		tree_1.Model = List_1;
		name_1.PackStart (NameCell_1, true);
		name_1.AddAttribute (NameCell_1, "text", 0);
		tree_1_add_data();
		
		//tree_2
		home_team_2.Title = "Home Team";
		away_team_2.Title = "Away Team";
		tree_2.AppendColumn(home_team_2);
		tree_2.AppendColumn(away_team_2);
		tree_2.Model = List_2;
		home_team_2.PackStart(homeCell_2, true);
		home_team_2.AddAttribute(homeCell_2, "text", 0);
		away_team_2.PackStart(awayCell_2, true);
		away_team_2.AddAttribute(awayCell_2, "text", 1);
		tree_2_add_data();
	}	
	
	public MainWindow (): base (Gtk.WindowType.Toplevel)
	{
		Build ();
		bool first = false;
		if (!File.Exists("league.db")){
			SqliteConnection.CreateFile("league.db");
			first = true;
		}
		string dsn = "Data Source=league.db;";
		DataConn = new SqliteConnection(dsn);
		DataConn.Open();
		DataComm.Connection = DataConn;
		if (first){
			DataComm.CommandText = "CREATE TABLE teams (ID INTEGER PRIMARY KEY, Name TEXT);";
			DataComm.ExecuteNonQuery();	
			DataComm.CommandText = "CREATE TABLE fixture (ID INTEGER PRIMARY KEY, Home TEXT, Away TEXT, Day INTEGER);";
			DataComm.ExecuteNonQuery();				
		}
		tree_conf();
	}
	
	protected void OnDeleteEvent (object sender, DeleteEventArgs a)
	{
		Application.Quit ();
		a.RetVal = true;
	}

	protected virtual void on_submit_1 (object sender, System.EventArgs e)
	{
		//if it's empty don't do anything
		string team = team_1.Text;
		if (team == ""){
			return;
		}
		//Insert data into the table
		DataComm.CommandText = string.Format("INSERT INTO teams VALUES (null, \"{0}\");", team);
		DataComm.ExecuteNonQuery();
		//Clear tree_1
		List_1.Clear();
		//Query database for teams
		tree_1_add_data();
	}

	protected virtual void on_generate_2 (object sender, System.EventArgs e)
	{
		generate_all_fixtures();
	}
}

"Is this an application that is available for free that you are modifying that we can download the original somewhere and get the 3rd party libraries installed? "
No it's my own app, it is made with Mono & GTK# on Linux instead of .Net

Which index is throwing the error: j or home ?

"j" is to big for "homea", "homea" is the right size.

"Is this an application that is available for free that you are modifying that we can download the original somewhere and get the 3rd party libraries installed? "
No it's my own app, it is made with Mono & GTK# on Linux instead of .Net

I've installed the Gtk# for .NET (http://www.go-mono.com/mono-downloads/download.html), but I still have one unresolved reference to Mono.Data.Sqlite.

I tried downloading the command-line program Sqlite-3 6 18.zip thinking I could reference the assembly and resolve the above, but no luck. Any suggestions?

"j" is to big for "homea", "homea" is the right size.

I don't see how "j" can be the culprit since j is always equal to "i" and "i" is always < numofix and homea is sized at numoffix.

Try adding adding this debug statement and assignment before the homea[j] assignment:

System.Diagnostics.Debug.Assert(i == j && j < numoffix && numoffix == homea.Length);
    homea[j] = "";
    homea[j] = teamsa[home];

The assert should happen if the empty string assignment (test) is going to fail...

I don't see how "j" can be the culprit since j is always equal to "i" and "i" is always < numofix and homea is sized at numoffix.

Try adding adding this debug statement and assignment before the homea[j] assignment:

System.Diagnostics.Debug.Assert(i == j && j < numoffix && numoffix == homea.Length);
    homea[j] = "";
    homea[j] = teamsa[home];

The assert should happen if the empty string assignment (test) is going to fail...

The error I get is:

Marshaling clicked signal
Exception in Gtk# callback delegate
  Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IndexOutOfRangeException: Array index is out of range.
  at MainWindow.generate_fixtures () [0x000cf] in /home/matio/Projects/leaguemanager/leaguemanager/MainWindow.cs:68 
  at MainWindow.generate_all_fixtures () [0x00043] in /home/matio/Projects/leaguemanager/leaguemanager/MainWindow.cs:84 
  at MainWindow.on_generate_2 (System.Object sender, System.EventArgs e) [0x00000] in /home/matio/Projects/leaguemanager/leaguemanager/MainWindow.cs:258 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] 
  --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] 
  at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00000] 
  at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00000] 
  at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] 
  at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs args) [0x00000] 
  at GLib.SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x00000] 
  at GLib.SignalClosure.MarshalCallback (IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data) [0x00000] 
   at GLib.ExceptionManager.RaiseUnhandledException(System.Exception e, Boolean is_terminal)
   at GLib.SignalClosure.MarshalCallback(IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data)
   at Gtk.Application.gtk_main()
   at Gtk.Application.Run()
   at leaguemanager.MainClass.Main(System.String[] args) in /home/matio/Projects/leaguemanager/leaguemanager/Main.cs:line 13

Well, you didn't report whether it was actually "j", and I am still not convinced it is.

In this method,

public void generate_team_array()
	{
		DataComm.CommandText = "SELECT * FROM teams;";
		DataReader = DataComm.ExecuteReader();
		teamsa = new string[numofteams];
		int i = 0;
		string returned;
		while (DataReader.Read()){
			returned = DataReader["Name"].ToString();
			teamsa[i] = returned;
			i++;
		}	
		DataReader.Close();
		numofteamsREAL = i - 1;
	}

why are you setting numofteamsREAL = i - 1 ? Shouldn't it be numofteamsREAL = i ?

It's too difficult to figure this out this way... If you tell me how to get the reference to the Mono.Data.Sqlite namespace, I'll help you figure this out.

The error text you posted is only partially useful and the line numbers it shows have probably moved since the code you posted prior.

New code:

using System;
using Gtk;
using Mono.Data.Sqlite;
using System.IO;

public partial class MainWindow: Gtk.Window
{	
	//SQLite variables
	static SqliteConnection DataConn;
    static SqliteCommand DataComm = new SqliteCommand();
    static SqliteDataReader DataReader;	
	string dsn;
	
	//tree_1 variables
	Gtk.TreeViewColumn name_1 = new Gtk.TreeViewColumn ();
	Gtk.ListStore List_1 = new Gtk.ListStore (typeof (string));
	Gtk.CellRendererText NameCell_1 = new Gtk.CellRendererText ();
	
	//tree_2 variables
	Gtk.TreeViewColumn home_team_2 = new Gtk.TreeViewColumn ();
	Gtk.TreeViewColumn away_team_2 = new Gtk.TreeViewColumn ();
	Gtk.TreeStore List_2 = new Gtk.TreeStore (typeof (string), typeof (string));
	Gtk.CellRendererText homeCell_2 = new Gtk.CellRendererText ();	
	Gtk.CellRendererText awayCell_2 = new Gtk.CellRendererText ();
	
	//tree_3 variables
	Gtk.TreeViewColumn home_team_3 = new Gtk.TreeViewColumn ();
	Gtk.TreeViewColumn away_team_3 = new Gtk.TreeViewColumn ();
	Gtk.TreeViewColumn home_team_score_3 = new Gtk.TreeViewColumn ();
	Gtk.TreeViewColumn away_team_score_3 = new Gtk.TreeViewColumn ();	
	Gtk.TreeStore List_3 = new Gtk.TreeStore (typeof (string), typeof (string), typeof (string), typeof (string));
	Gtk.CellRendererText homeCell_3 = new Gtk.CellRendererText ();	
	Gtk.CellRendererText awayCell_3 = new Gtk.CellRendererText ();
	Gtk.CellRendererText homescoreCell_3 = new Gtk.CellRendererText ();
	Gtk.CellRendererText awayscoreCell_3 = new Gtk.CellRendererText ();
	
	//Iter
	Gtk.TreeIter iter_2;
	Gtk.TreeIter iter_3;
	
	int numofteams;
	int numofteamsOLD;
	string[] teamsa;
	string[] homea;
	string[] awaya;
	int[,] fixturea;
	
	public void generate_fixtures()
	{
		Random rand = new Random();
		int home;
		int away;
		int numoffix = numofteams/2;
		int j = 0;
		homea = new string[numoffix];
		awaya = new string[numoffix];
		int[] teamsused = new int[numofteams];
		int k = 0;
		for (int i = 0; i < numoffix; i++){
			do{
				home = rand.Next(0, numofteams);
				away = rand.Next(0, numofteams);
				k++;
			} while (home == away || fixturea[home,away] != 0 || teamsused[home] != 0 || teamsused[away] != 0);
			fixturea[home,away] = 1;
      		System.Diagnostics.Debug.Assert(i == j && j < numoffix && numoffix == homea.Length);
      		homea[j] = "";
      		homea[j] = teamsa[home];	
			homea[j] = teamsa[home];
			awaya[j] = teamsa[away];
			teamsused[home] = 1;
			teamsused[away] = 1;
			j++;
		}
	}
	
	public void generate_all_fixtures()
	{
		fixturea = new int[numofteams,numofteams];
		DataComm.CommandText = "DELETE FROM fixture;";
		DataComm.ExecuteNonQuery();	
		int blah = (numofteams-1) * 2;
		for (int i = 0; i < blah; i++){
			generate_fixtures();
			for (int j = 0; j < numofteams/2; j++){
				DataComm.CommandText = string.Format("INSERT INTO fixture VALUES (null, \"{0}\", \"{1}\", {2});", homea[j], awaya[j], i+1);
				DataComm.ExecuteNonQuery();	
				DataComm.CommandText = string.Format("INSERT INTO results VALUES (null, \"{0}\", null, \"{1}\", null, {2});", homea[j], awaya[j], i+1);
				DataComm.ExecuteNonQuery();		
			}
		}
		tree_2_add_data();
	}	
	
	public void generate_team_array()
	{
		DataComm.CommandText = "SELECT * FROM teams;";
		DataReader = DataComm.ExecuteReader();
		teamsa = new string[numofteams];
		int i = 0;
		string returned;
		while (DataReader.Read()){
			returned = DataReader["Name"].ToString();
			teamsa[i] = returned;
			i++;
		}	
		DataReader.Close();
	}
	
	public void tree_1_add_data()
	{
		numofteams = 0;
		DataComm.CommandText = "SELECT * FROM teams;";
		DataReader = DataComm.ExecuteReader();
		string returned;
		while (DataReader.Read()){
			returned = DataReader["Name"].ToString();
			List_1.AppendValues(returned);
			numofteams += 1;
		}
		DataReader.Close();
		generate_team_array();
	}
	
	public void tree_2_add_data()
	{
		string day;
		List_2.Clear();
		for (int i = 0; i < numofteams/2; i++){
			DataComm.CommandText = string.Format("SELECT * FROM fixture where Day = {0};", i+1);
			DataReader = DataComm.ExecuteReader();
			if (DataReader.HasRows){
				day = string.Format("Day {0}", i+1);
				iter_2 = List_2.AppendValues(day);
			} else {
				DataReader.Close();
				return;
			}
			while (DataReader.Read()){
				List_2.AppendValues(iter_2, DataReader["Home"].ToString(), DataReader["Away"].ToString());
				numofteams += 1;
			}
			DataReader.Close();	
		}
	}
	
	public void tree_3_add_data(){
		string day;
		List_3.Clear();
		for (int i = 0; i < numofteams/2; i++){
			DataComm.CommandText = string.Format("SELECT * FROM results where Day = {0};", i+1);
			DataReader = DataComm.ExecuteReader();
			if (DataReader.HasRows){
				day = string.Format("Day {0}", i+1);
				iter_3 = List_3.AppendValues(day);
			} else {
				DataReader.Close();
				return;
			}
			while (DataReader.Read()){
				List_3.AppendValues(iter_3, DataReader["Home"].ToString(), DataReader["Home_Score"].ToString(), DataReader["Away"].ToString(), DataReader["Away_Score"].ToString());
				numofteams += 1;
			}
			DataReader.Close();	
		}
	}
	
	public void tree_conf()
	{
		//tree_1
		name_1.Title = "Name"; 
		tree_1.AppendColumn(name_1);
		tree_1.Model = List_1;
		name_1.PackStart (NameCell_1, true);
		name_1.AddAttribute (NameCell_1, "text", 0);
		tree_1_add_data();
		
		//tree_2
		home_team_2.Title = "Home Team";
		away_team_2.Title = "Away Team";
		tree_2.AppendColumn(home_team_2);
		tree_2.AppendColumn(away_team_2);
		tree_2.Model = List_2;
		home_team_2.PackStart(homeCell_2, true);
		home_team_2.AddAttribute(homeCell_2, "text", 0);
		away_team_2.PackStart(awayCell_2, true);
		away_team_2.AddAttribute(awayCell_2, "text", 1);
		tree_2_add_data();
		
		//tree_3
		home_team_3.Title = "Home Team";
		away_team_3.Title = "Away Team";
		home_team_score_3.Title = "Home Score";
		away_team_score_3.Title = "Away Score";
		tree_3.AppendColumn(home_team_3);
		tree_3.AppendColumn(home_team_score_3);
		tree_3.AppendColumn(away_team_3);
		tree_3.AppendColumn(away_team_score_3);
		tree_3.Model = List_3;
		home_team_3.PackStart(homeCell_3, true);
		home_team_3.AddAttribute(homeCell_3, "text", 0);
		home_team_score_3.PackStart(homescoreCell_3, true);
		home_team_score_3.AddAttribute(homescoreCell_3, "text", 1);		
		away_team_3.PackStart(awayCell_3, true);
		away_team_3.AddAttribute(awayCell_3, "text", 2);
		away_team_score_3.PackStart(awayscoreCell_3, true);
		away_team_score_3.AddAttribute(awayscoreCell_3, "text", 3);		
		tree_3_add_data();		
	}	
	
	public MainWindow (): base (Gtk.WindowType.Toplevel)
	{
		Build ();
		bool first = false;
		if (!File.Exists("league.db")){
			SqliteConnection.CreateFile("league.db");
			first = true;
		}
		string dsn = "Data Source=league.db;";
		DataConn = new SqliteConnection(dsn);
		DataConn.Open();
		DataComm.Connection = DataConn;
		if (first){
			DataComm.CommandText = "CREATE TABLE teams (ID INTEGER PRIMARY KEY, Name TEXT);";
			DataComm.ExecuteNonQuery();	
			DataComm.CommandText = "CREATE TABLE fixture (ID INTEGER PRIMARY KEY, Home TEXT, Away TEXT, Day INTEGER);";
			DataComm.ExecuteNonQuery();		
			DataComm.CommandText = "CREATE TABLE results (ID INTEGER PRIMARY KEY, Home TEXT, Home_Score INTEGER, Away TEXT, Away_Score INTEGER, Day INTEGER);";
			DataComm.ExecuteNonQuery();	
		}
		tree_conf();
	}
	
	protected void OnDeleteEvent (object sender, DeleteEventArgs a)
	{
		Application.Quit ();
		a.RetVal = true;
	}

	protected virtual void on_submit_1 (object sender, System.EventArgs e)
	{
		//if it's empty don't do anything
		string team = team_1.Text;
		if (team == ""){
			return;
		}
		//Insert data into the table
		DataComm.CommandText = string.Format("INSERT INTO teams VALUES (null, \"{0}\");", team);
		DataComm.ExecuteNonQuery();
		//Clear tree_1
		List_1.Clear();
		//Query database for teams
		tree_1_add_data();
	}

	protected virtual void on_generate_2 (object sender, System.EventArgs e)
	{
		generate_all_fixtures();
	}

	protected virtual void on_submit_3 (object sender, System.EventArgs e)
	{
	}
}

I don't know how to install SQLite in Windows, I'm running Ubuntu.
Thanks for trying to help

If you've installed SQLite & created a new project right-click on the references & check Mono.SQLite (or whatever it is)

OK, that error is indicating that home index is out of range because that is line 68 and it did not fail at line 67, which is where we have already ensured that "j" is not out of range because that line did not throw the error:

homea[j] = ""; // line 67 OK
      		homea[j] = teamsa[home]; // line 68 failed

EDIT: What is the value of "numofteams" when this is executing?

OK, that error is indicating that home index is out of range because that is line 68 and it did not fail at line 67, which is where we have already ensured that "j" is not out of range because that line did not throw the error:

homea[j] = ""; // line 67 OK
      		homea[j] = teamsa[home]; // line 68 failed

EDIT: What is the value of "numofteams" when this is executing?

16, which is 4x what it should be.

So, did you determine the discrepancy in "numofteams" and get the index out of range fixed?

Not yet

Bump

Take a look at all the DataReader loops where you are incrementing numofteams for all of the various list loads...

Without the ability to up and run this project, it's difficult to follow everything that might be happening. What I advise, for starters, is to not rely on numofteams increment as it is currently, and just use the teamsa.Length property for determining the actual number of teams you have loaded into the teamsa string array:

// set the var to be whatever the actual number of teams loaded is...
    int numOfTeams = teamsa.Length;
    // then, assuming number of fixed teams is half the even portion of total teams...
    int numOfFixed = numOfTeams / 2;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.