Solved

Application-Generated Column Values in DataGridView on New Record

Posted on 2007-12-06
3
580 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
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Video Player 11 23
VB.NET (2008) - Refactoring Question 2 21
help with regular expression to search string 6 24
Winform Module - What is the ASP.Net equiv 2 20
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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