I have a List containing a number of transaction objects. What I'm trying to do is display these transaction objects in the Datagridview control when the form loads, basically Datagridview needs to represent something from the transaction register to display data for each of the transaction objects in the list.
I have to admit a lack of experience when it comes to using Datagridviews, and I have difficulty understanding what I need to do here.
My question is: how do I get information about each of the objects in the list that will be displayed in Datagridview?
Here is my code.
First transaction class:
public class Transaction { // Class properties private decimal amount; private string type; private decimal balance; private string date; private string transNum; private string description; // Constructor to create transaction object with values set. public Transaction(decimal amount, string type, decimal currBal, string date, string num, string descrip) { this.amount = amount; this.type = type; this.balance = currBal; this.date = date; this.transNum = num; this.description = descrip; } // Get and Set accessors to allow manipulation of values. public decimal Amount { get { return amount; } set { amount = value; } } public string Type { get { return type; } set { type = value; } } public decimal Balance { get { return balance; } set { balance = value; } } public string Date { get { return date; } set { date = value; } } public string TransNum { get { return transNum; } set { transNum = value; } } public string Description { get { return description; } set { description = value; } } public decimal addCredit(decimal balance, decimal credit) { decimal newBalance; newBalance = balance + credit; return newBalance; } public decimal subtractDebit(decimal balance, decimal debit) { decimal newBalance; newBalance = balance - debit; return newBalance; } } }
Now the code of the "Registration" form:
public partial class Register : Form { List<Transaction> tranList = new List<Transaction>(); public Register(List<Transaction> List) { InitializeComponent(); this.tranList = List; } private void Register_Load(object sender, System.EventArgs e) {
And here is the result that I get. 
c # winforms datagridview
morris295
source share