Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Adapting DataGridView to Data Structure

$
0
0

I'm designing a small desktop Windows Forms application to store user account information, i.e. usernames and passwords. I'm using C#/LINQ to SQL and SQL CE.

The application allows the user to create account categories, e.g. social media/work/banking, and create accounts under those categories. The application enables users to create "dynamic" accounts, meaning each category can have different fields. For example, accounts under the "Social Media" category may only need username and password fields. Accounts under "Banking" may need a field for routing number, account number, etc.

Here's the ERD for the data structure (relationships should be obvious but were not yet defined in this screenshot):

enter image description here

Here's a cheesy, color-coded prototype of how the front-end will work:

enter image description here

The problem I'm facing is how to populate the DataGridView with all accounts/credentials for a given category. I believe I should add a new row to the DataGridView for each account in the database, but I'm not sure how to populate that row with the credentials belonging to it. My first guess is that I would need to query all credentials matching the row's account_id and insert it into the correct field/column. Here's some logical code that seems to imply this would be a messy solution:

foreach(Account acct in context.Accounts){
    dataGridView.Rows.Add()foreach(Credential cred in context.Credentials){if(cred.account_id == acct.id){// check to see which field the credential belongs to// and insert it into that field for the current row}}}

Any suggestions on a better solution? I can see a lot of problems with this down the road. As a beginner, I'm very open to re-structuring the database or alternative ideas for the GUI. Let me know if you need clarification on anything.


When I was a young warthooooooooog.


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>