C
C#3mo ago
banger

Simple Bank program, DataGridView issue

Hello guys, I'm beginner and I was working on some simple bank app in windows forms, I ran into issue where I can not select the grid, it just gives me error for just selecting it(clicking it), can someone help me out, I couldn't troubleshoot it
8 Replies
banger
bangerOP3mo ago
:sadge:
Mayor McCheese
Mayor McCheese3mo ago
You'll likely need to provide more details What errors are you getting? What does the code look like? It's likely the generic windows forms uncaught exception handling Error wise
banger
bangerOP3mo ago
When I get home i will provide the errors and other details
banger
bangerOP3mo ago
No description
No description
banger
bangerOP3mo ago
By the way on the first picture when u take your cursor to the row, the little arrow is shown on the left, it does not show up on my grid, and the second picture is the error it gives me when i try to select it @Mayor McCheese
Mayor McCheese
Mayor McCheese3mo ago
You've got an uncaught exception bubbling all the way to the top. What event handlers do you have defined on your grid?
banger
bangerOP3mo ago
namespace BankAccountsApp
{
public partial class Form1 : Form
{


List<BankAccount> BankAccounts = new List<BankAccount>();


public Form1()
{
InitializeComponent();


dataGridView1.DataSource = BankAccounts;


}

private void CreateAccountBtn_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(OwnerTxt.Text))
{
MessageBox.Show("Enter the username!");
return;
}

BankAccount bankAccount = new BankAccount(OwnerTxt.Text);
BankAccounts.Add(bankAccount);

RefreshGrid();
OwnerTxt.Text = string.Empty;
}


private void RefreshGrid()
{
dataGridView1.DataSource = null;
dataGridView1.DataSource = BankAccounts;

}

private void DepositBtn_Click(object sender, EventArgs e)
{
if(dataGridView1.SelectedRows.Count == 1 && AmountNum.Value > 0)
{
BankAccount selectedBankAccount = dataGridView1.SelectedRows
[0].DataBoundItem as BankAccount;

selectedBankAccount.Balance += AmountNum.Value;
RefreshGrid();
}
}
}
}
namespace BankAccountsApp
{
public partial class Form1 : Form
{


List<BankAccount> BankAccounts = new List<BankAccount>();


public Form1()
{
InitializeComponent();


dataGridView1.DataSource = BankAccounts;


}

private void CreateAccountBtn_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(OwnerTxt.Text))
{
MessageBox.Show("Enter the username!");
return;
}

BankAccount bankAccount = new BankAccount(OwnerTxt.Text);
BankAccounts.Add(bankAccount);

RefreshGrid();
OwnerTxt.Text = string.Empty;
}


private void RefreshGrid()
{
dataGridView1.DataSource = null;
dataGridView1.DataSource = BankAccounts;

}

private void DepositBtn_Click(object sender, EventArgs e)
{
if(dataGridView1.SelectedRows.Count == 1 && AmountNum.Value > 0)
{
BankAccount selectedBankAccount = dataGridView1.SelectedRows
[0].DataBoundItem as BankAccount;

selectedBankAccount.Balance += AmountNum.Value;
RefreshGrid();
}
}
}
}
these
Mayor McCheese
Mayor McCheese3mo ago
If you put a break point (F9) on the line you want a breakpoint at; at the start of each event handler method you can step through (F10) and examine the state of your data grid, etc

Did you find this page helpful?