Tuesday, 21 April 2009

New row default values in DataGridView

I was looking for a nice way of displaying default values in a datagridview when a user creates a new row.


At first I looked at settings in the binding source but there wasn't anything that stood out. Then I looked att he table adapter again there wasn't anything I could use.


Finally I found that it was an event in dataGridView that was required. The event is called 'DefaultValuesNeeded'. It can be used to specify default values for any row in a DataGridView. It is fired when you create a new row in a DatagridView.


Below is a C# example from http://msdn.microsoft.com/en-us/library/b22t666e.aspx


private void dataGridView1_DefaultValuesNeeded(object sender,
System.Windows.Forms.DataGridViewRowEventArgs e)
{
e.Row.Cells["Region"].Value = "WA";
e.Row.Cells["City"].Value = "Redmond";
e.Row.Cells["PostalCode"].Value = "98052-6399";
e.Row.Cells["Region"].Value = "NA";
e.Row.Cells["Country"].Value = "USA";
e.Row.Cells["CustomerID"].Value = NewCustomerId();
}

Very useful and it is something I will be using a lot.

22 comments:

for IT the said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru Dot Net Training in Chennai. Nowadays Dot Net has tons of job opportunities on various vertical industry.
or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

john kevin said...

I have to voice my passion for your kindness giving support to those people that should have guidance on this important matter.

java training in bangalore

Apsara G said...

Excellent Sharing. You have done a great job. I gathered lots of new information... Java Training in Chennai

Apsara G said...

Excellent Article ...thank u for sharing, such a valuable content Learners to get good knowledge after reading this article... Java Training in Chennai

Apsara G said...

Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep updating your blog... Java Training in Chennai

Apsara G said...

It’s Good to share good things, Explained well...
RPA Training in Chennai | Blue Prism Training in Chennai

Apsara G said...

It’s Good to share good things, Explained well...
RPA Training in Chennai | Blue Prism Training in Chennai

Apsara G said...

It’s Good to share good things, Explained well...
RPA Training in Chennai | Blue Prism Training in Chennai

gowsalya said...

Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
Digital Marketing Training in Chennai

Digital Marketing Training in Bangalore

digital marketing training in tambaram

digital marketing training in annanagar

Rufus Rufus said...

It?s hard to find knowledgeable people on this topic, but you sound like you know what you?re talking about! Thanks esfileexplorerapkz.info

Mouni yoga said...

After seeing your article I want to say that the presentation is very good and also a well-written article with some very good information which is very useful for the readers....thanks for sharing it and do share more posts like this.
python training institute in chennai
python training in Bangalore
python training in pune
python training institute in chennai
python training in velachery
python online training

ragini k said...

Very good brief and this post helped me alot. Say thank you I searching for your facts. Thanks for sharing with us!

Blueprism training in tambaram

Blueprism training in annanagar

Blueprism training in velachery

ragini k said...

Very good brief and this post helped me alot. Say thank you I searching for your facts. Thanks for sharing with us!

Blueprism training in tambaram

Blueprism training in annanagar

Blueprism training in velachery

Nila shri said...

This looks absolutely perfect. All these tiny details are made with lot of background knowledge. I like it a lot. 

Data science training in tambaram | Data Science training in anna nagar
Data Science training in chennai | Data science training in Bangalore
Data Science training in marathahalli | Data Science training in btm

Sri Nithya said...

Excellent and useful blog admin, I would like to read more about this topic.
Blue Prism Training in Chennai | Blue Prism Training | Blue Prism Training Chennai | Blue Prism Training in Velachery | Blue Prism Training in Tambaram | UiPath Training in Chennai

sudha P said...

All the points you described so beautiful. Every time i read your i blog and i am so surprised that how you can write so well.
java training in chennai | java training in bangalore

java online training | java training in pune

Anonymous said...

Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.

angularjs Training in chennai
angularjs Training in chennai

angularjs-Training in tambaram

angularjs-Training in sholinganallur

angularjs-Training in velachery

Sumaya Manzoor said...

I was totally impressed with your content, keep posting.
Selenium training in chennai
Selenium training institute in Chennai
iOS Course Chennai
Digital Marketing Training in Chennai
android courses in chennai
android mobile apps development training in chennai

pavithra dass said...

Thank you for sharing such great information with us. I really appreciate everything that you’ve done here and am glad to know that you really care about the world that we live in.
Web Designing Course in chennai
PHP Training in Chennai
Web Designing Institute in Chennai
Web Designing Training Institutes in Chennai
PHP Course in Chennai
PHP Training Institute in Chennai

Anjali Siva said...

Informative post, thanks for taking time to share this page.
RPA Training in Chennai
RPA course
Robotics Process Automation Training in Chennai
RPA courses in Chennai
Blue Prism Training Chennai
UiPath Training in Chennai

Praylin S said...

Great blog! I was actually looking for these kinds of posts. I'm glad that I came across here. Looking forward for more informative posts from you.
Javascript Training in Chennai | Javascript Course | Javascript Training Institute in Chennai | Javascript Training Courses

Anoushka Sakthi said...

I am always searching online for articles that can help. There is obviously a lot to know about this. I think you made some good points
Selenium Training in Chennai
Selenium Training
iOS Training in Chennai
French Classes in Chennai
Big Data Training in Chennai
web designing course in chennai
web designing training in chennai