Solved

Application-Generated Column Values in DataGridView on New Record

Posted on 2007-12-06
3
582 Views
Last Modified: 2013-11-26
Application-Generated Column Values in DataGridView on New Record

I have a DataGridView which I am using to enter new records to a table with 5 columns/fields. However, values for two of the fields are generated by the program automatically using some algorith (not the database AutoNumber). As such, they should not be entered in the datagrid view. The idea is that when i click a "New Record" button, the corresponding two columns are disabled to disallow and the values generated and inserted in the respective cells. The user can then enter remainder of data.

My problem is how to have the Automatically generated values in the cells. Any hints?
0
Comment
Question by:gkinu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Author Comment

by:gkinu
ID: 20418672
I have realized that there is a VAlue property for each cell.

I am now using it as follows
           string GeneratedVal=SomeFunction();
           dataGridView1.Rows[0].Cells[3].Value = GeneratedVal;

Open in new window

0
 
LVL 1

Author Comment

by:gkinu
ID: 20418714
I have realized that there is a VAlue property for each cell.

I am now using it as follows
string GeneratedVal=SomeFunction();
dataGridView1.Rows[0].Cells[3].Value = GeneratedVal

Open in new window

0
 
LVL 6

Accepted Solution

by:
so3 earned 125 total points
ID: 20418730
you can also use this for setting a default value for the new row.

        private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
            if (e.RowIndex >= 0)
                dataGridView1.Rows[e.RowIndex].Cells[3].Value = GeneratedVal;
        }

        private void dataGridView1_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
        {
            e.Row.Cells[3].Value = GeneratedVal;
        }
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question