I have a issue I cannot get my head around.
I have a main GUI in where I add data, 12 columns. Each data on 1 row as it comes in. This data is pushed into a array which is accessible globally. the array is dynamic 2D, growing each time I enter a set of data.
I wish to have a button that when pressed displays all the currently available data held in the array. If I can edit it then its a step further but at the minute I just need to be able to view the contents of my array.
My code is long as there are many buttons, listboxes doing different things. If any one has an idea I can mail them my code.
Thanks, Timunjin
Loading
jawaad bokhariPosted Jun 13, 2012, 7:28 AM
:)
FroglegPosted Jun 13, 2012, 6:43 AM
Look here
jawaad bokhariPosted Jun 13, 2012, 3:21 AM
FroglegPosted Jun 12, 2012, 3:51 PM
jawaad bokhariPosted Jun 12, 2012, 4:54 AM
-----------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MyProject
{
public partial class Form2 : Form
{
public static Form2 Fm2 = null;
public string[,] secondArray = null;
public Form2()
{
InitializeComponent();
}
public void Form2_Load(object sender, EventArgs e)
{
Fm2 = this;
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
jawaad bokhariPosted Jun 12, 2012, 4:53 AM
I need to access the array tradebuilder and put the data into a listbox which is displayed in Form2.
Any Ideas?
-----------------------------
Form1
namespace MyProject
{
public partial class Form1 : Form
{
//#################################
//GLOBAL variables
string isin;
string kv;
string price;
string tdate;
string sdate;
string tdID;
string tradeID;
int kv_number;
int trade_number=0;
double Price;
//##################################
//GLOBAL ARRAY
public string[,] tradebuilder = new string[1, 12];
//##################################
//##################################
//##################################
public void ResizeArray(ref string[,] original, int cols, int rows)
{
//create a new 2 dimensional array with
//the size we want
string[,] newArray = new string[rows, cols];
//copy the contents of the old array to the new one
Array.Copy(original, newArray, original.Length);
//set the original to the new array
original = newArray;
}
public static Form1 Fm1 = null;
public Form1()
{
InitializeComponent();
string[] stocknames = File.ReadAllLines("StockNameDE.txt");
foreach (var line in stocknames)
{
string[] tokens = line.Split('\n');
comboBox2.Items.Add(tokens[0]);
}
}
//Initialising area for date
private void Form1_Load(object sender, EventArgs e)
{
DateTime td_date = DateTime.Today.Subtract(TimeSpan.FromDays(1));
dateTimePicker1.Value = td_date;
}
//COUNTRY CODE, Eg. DE,CH
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string ccode;
ccode = comboBox1.SelectedItem.ToString();
}
private void button4_Click(object sender, EventArgs e)
{
}
//ISIN SELECTION
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
string stockname;
//string isin;
stockname = comboBox2.SelectedItem.ToString();
MyFunction isinget = new MyFunction();
isin = isinget.StockToIsinDE(stockname);
}
//Buy Sell Section
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
string buysell = string.Empty;
buysell = comboBox3.SelectedItem.ToString();
}
//QUANTITY
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
string qty;
int qtyint;
if(textBox1.Text==String.Empty)
{
textBox2.Focus();
}
else
{
qty = textBox1.Text;
qtyint = Convert.ToInt32(qty);
textBox2.Focus();
}
}
}
//PRICE
private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
price = textBox2.Text;
Price = Convert.ToDouble(price);
textBox3.Focus();
}
}
//COUNTERPARTY
private void textBox3_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
kv = textBox3.Text;
kv_number = Convert.ToInt32(kv);
}
}
//DATE
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
DateTime td_date = dateTimePicker1.Value;
DateTime sd_date = td_date.AddWorkDays(2);
tdate = td_date.ToString("ddMMyyyy");
tdID = td_date.ToString("ddMMyyyy");
sdate = sd_date.ToString("ddMMyyyy");
}
//Add Trade - public
public void button5_Click(object sender, EventArgs e)
{
//trade number has increase by one.
trade_number = trade_number + 1;
//create the string for the trade ID
tradeID = tdID + Convert.ToString(trade_number);
//add all the data to one line/arrary and clear all fields.
//string trade_date = ;
/* structure is
tradenum;tradedate;settdate;buysell;quantity;isin;name;price;currency;value;counterparty;account
*/
string buysell = comboBox3.Text;
string region = comboBox1.Text;
string quantity = textBox1.Text;
string name = comboBox2.Text;
string price = textBox2.Text;
string cp = textBox3.Text;
string value = String.Empty;
//to get the value
double prc = 0.0;
double val = 0.0;
int qty = 0;
prc = Convert.ToDouble(price);
qty = Convert.ToInt32(quantity);
val = prc * qty;
value = Convert.ToString(val);
string acc = "7908955085";
string currencycode = String.Empty;
if (region == "DE") {currencycode = "EUR";}
else if (region == "CH") {currencycode = "CHF";}
ResizeArray(ref tradebuilder, 12, trade_number);
tradebuilder[trade_number-1, 0] = tdID;
tradebuilder[trade_number-1, 1] = tdate;
tradebuilder[trade_number-1, 2] = sdate;
tradebuilder[trade_number-1, 3] = buysell;
tradebuilder[trade_number-1, 4] = quantity;
tradebuilder[trade_number-1, 5] = isin;
tradebuilder[trade_number-1, 6] = name;
tradebuilder[trade_number-1, 7] = price;
tradebuilder[trade_number-1, 8] = currencycode;
tradebuilder[trade_number-1, 9] = value;
tradebuilder[trade_number-1, 10] = cp;
tradebuilder[trade_number-1, 11] = acc;
//resetting variables for the next trade
comboBox1.ResetText(); comboBox2.ResetText(); comboBox3.ResetText();
textBox1.ResetText(); textBox2.ResetText(); textBox3.ResetText();
}
//view trades that have been created so far in a table.
// I want to be able to generate on Form 2 the data that is stored in tradebuilder so far.
public void button1_Click(object sender, EventArgs e)
{
if (Form2.Fm2 == null)
{
Form2.Fm2 = new Form2();
Form2.Fm2.Show();
}
else
{
Form2.Fm2.Show();
Form2.Fm2.BringToFront();
}
button1.Enabled = true;
}
}
}
FroglegPosted Jun 11, 2012, 4:39 PM
http://www.c-sharpcorner.com/Forums/Thread/175259/C-Sharp-winforms-multipleforms-task.aspx