?
Solved

Application-Generated Column Values in DataGridView on New Record

Posted on 2007-12-06
3
Medium Priority
?
585 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 375 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

Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

752 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