How to get out information from a DataGridView?
I am working on program that calculate the GPAs for university students in C#.
I have made 开发者_JS百科a gridview that contains columns for each subject. Its mark as letter and number. After the user "student" insert his/her subject I want to let the user click a button that will get the mark and the number of the credit hours of each subject. Calculate the GPA for the student and put the result in a textbox.
I am having trouble getting started. Any advice for a good place to start?
To answer just the question in your title:
To get value from the current row, first capture the row:
DataGridViewRow r = MyDataGridView.CurrentRow;
To get the value from cell 0:
string v = (string)r.Cells[0].Value;
What I see from your question you are having difficulty how to put the requirement in one place.
I'm assuming you already have the user requirements (it looks very simple) and I give basic steps you go through, it is not accurate and it doesn't fit for all type of projects, but your case is very simple and I think it is enough to do the work.
- first you will need to create a flow, the steps the user will go through to accomplish the process.
- then you will need the basic interface to let you have at least to know what controls you will need.
- after that you will make the data structure (mostly the database schema) to know how the data will be stored and related to each other.
- then you will create the business logic to implement your requirements.(the coding part)
- and Last you will glue all the things and attach the code that wrote to the events in the interface based on the flow you made it at the first step.
I hope this helps.
I'm not sure about what you are trying to do, but you can take a look here: http://www.c-sharpcorner.com/Articles/ArticleListing.aspx?SectionID=1&SubSectionID=191
I've solved lots of my WPF dumb design problems with these articles :P
精彩评论