Hi, I'm beginner programmer and I'm trying to graphically represent an array.
I have class named Macierz witch I use to make some calculation from values in array. Now I want to show user graphical representation of part or all of my array and allow him to make changes. Important notes:
- Values inside won't ever change from program, only user can change values.
- I want to keep using static array for calculations.
- I want Macierz to be usable in Console Application.
- I want to show rows and columns numbers on the edge and last column "Suma" to automatically reflect changes made by user (this column don't exist in original array).
There is some code:
- From Macierz.cs:
public class Macierz { public Macierz(ulong A, ulong B) { this.a = A; this.b = B; this.M = new BigInteger[A, B]; } private BigInteger[,] M; public BigInteger this[ulong A, ulong B] { get { return M[A, B]; } set { M[A, B] = value; } } public DataTable ToDataTable(ulong AStart, ulong ACount, ulong BStart, ulong BCount) { if (AStart >= a) AStart = a - 1; if (BStart >= b) BStart = b - 1; ulong AStop = AStart + ACount; ulong BStop = BStart + BCount; if (AStop > a) AStop = a; if (BStop > b) BStop = b; DataTable table = new DataTable(); DataRow tmp; BigInteger BItmp; for (ulong i = BStart; i < BStop; i++) table.Columns.Add(i.ToString(), typeof(BigInteger)); table.Columns.Add("Suma", typeof(BigInteger)); for (ulong i = AStart; i < AStop; i++) { tmp = table.NewRow(); for (ulong j = BStart; j < BStop; j++) tmp[j.ToString()] = M[i, j]; BItmp = 0; for (ulong j = 0; j < B; j++) BItmp += M[i, j]; tmp["Suma"] = BItmp; table.Rows.Add(tmp); } return table; } } }
- From MainWindow.xaml:
<DataGrid x:Name="TabelaDataGrid" AutoGenerateColumns="True" CellEditEnding="TabelaDataGrid_CellEditEnding" />
- From MainWindow.xaml.cs:
private void PokazButton_Click(object sender, RoutedEventArgs e) { this.Cursor = Cursors.Wait; if (czyCala.IsChecked == true) GridTabela = M.ToDataTable(0, M.A, 0, M.B); else GridTabela = M.ToDataTable(VA, VACount, VB, VBCount); TabelaDataGrid.DataContext = this; TabelaDataGrid.ItemsSource = GridTabela.DefaultView; this.Cursor = null; } private void TabelaDataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { //Here I tried to insert some code so values changed by user in DataTable object will change values in original array but I don't know how to do this. }
I'm not sure it is good way to this. I can change my approach if there are better solutions. Sorry for all grammatical/ language mistakes (English isn't my main) and thank you in advance.