Solved

Application-Generated Column Values in DataGridView on New Record

Posted on 2007-12-06
3
579 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
  • 2
3 Comments
 
LVL 1

Author Comment

by:gkinu
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now