473,770 Members | 3,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGridView user added row help

6 New Member
Hello everyone,

What I'm currently trying to do is allow a user to add a row to my datagridview. I have AllowUserToAddR ows set to true. And the empty now does appear at the bottom of my data. The datagridview has a data source set to a datatable. The code currently allows a user to add the row properly and the data is making it into the datatable. So what I want to do know is auto fill in an ID column as soon as the user starts editing the datagridview. I'm just having trouble knowing which event to handle to do this. Optimally I want to handle dataTable.table NewRow, but that event is never throw even though the user is adding a new row to the table. So I've been trying to use datagridview.Ce llValueChanged and then check if the cell being edited is part a new row, but haven't found much success. I also tried ddatagridview.N ewRowsAdded, but that event is thrown when a user just clicks on the empty column on the bottom and hasn't even made an edit yet. The Id column that I'm auto filling is supposed to be one more than the larges existing ID in that column.

here is what I have so far:
Expand|Select|Wrap|Line Numbers
  1. private void EditMade(object sender, DataGridViewCellEventArgs e)
  2. {
  3.    if (e.RowIndex == dataGridView1.Rows.Count-2)
  4.    {
  5.       double largestID=FindLargestID();
  6.       dataGridView1.CellValueChanged -= new DataGridViewCellEventHandler(EditMade);
  7.       dataGridView1.Rows[dataGridView1.Rows.Count - 2].Cells[sortedColumn].Value = largestID + 1;
  8.       dataGridView1.CellValueChanged += new DataGridViewCellEventHandler(EditMade);
  9.    }
  10. }
  11.  
  12.  
Hopefully someone out there can understand what I want this thing to do.
Thanks for the help!
Oct 25 '06 #1
0 2174

Sign in to post your reply or Sign up for a free account.

Similar topics

7
8366
by: Robert Koller | last post by:
Hello i have this problem: In a DataGridView the user work with data from a DataSet. on Start the row index from datagridview is the same as the row index from the dataset. Also: DataGridView.Rows(5) <=====> DataSet.Rows(5) .
3
17244
by: Bob | last post by:
Thinking two things, 1- Creating a userControl -yeah you guessed it, a multi column drop down combobox - I've looked at several articles and did not find what I need, one that's bindable and that I can use in a datagrid view. 2- Extending the datagridview so that it can be added to the list in the column types when editing columns in the datagridview. I'm really getting PO'd at Microsoft for not including a multi column combobox both a...
0
1584
by: Pieter Coucke | last post by:
Hi, I have a DataGridView, that contains a list of Articles, which can be added (automaticly via the AllowUserToAddRows) and changed by the user. The current item is also displayed in textboxes under the datagridview, to give more space for the user to change the item. But I'm getting some werid results with it: - When I add the first item to the DataGridView, and I change the values of the cells in the DataGridView, these values are...
10
7798
by: michael sorens | last post by:
Is it possible to store an unbound DataGridView component into a setting? I naively tried defining a Setting that is a DataGridView called DGV, then simply assigning it: Properties.Settings.Default.DGV = myDataGridView; After I closed the program, the user.config file shows an empty value, so apparently that is not the way to do it.
7
16466
by: Ryan | last post by:
I have a DataGridView which displays numeric (Int32) data from an underlying database. I want the numbers to be displayed in numeric format "#,###" (with commas). I want to also limit the user so they can only input numerical values. Is there any way to do this? Currently my formatting works but if the user enters a value manually the formatting is not applied to the new value. Also I haven't found a way to allow only numerical input....
1
8509
by: =?Utf-8?B?RGF0YUdyaWRWaWV3IGFkZCByb3cgZHluYW1pY2Fs | last post by:
Hi, I am working on the windows application. I created a form Form1 to list records. I used datagridview to show data and bound it to a dataadapter. User can click Update button in Form1 to open a new dialog window Form2 to update selected record and also add new records. When user closes the Form2, the Form1's records should be updated (New records should be added and updated record should be updated.) And we also want to stay in the...
1
2477
by: Jeff | last post by:
Hey ..NET 2.0 I've created a User Control which contain a DataGridView. This User Control is displayed on a TabPage. This TabPage is added to the TabControl during runtime. The problem is this: Lets say if I set the size on the DataGridView to width=400px &
3
9690
by: jehugaleahsa | last post by:
Hello: I am binding a DataGridView with a BindingList<T>, where T is a custom business object that implements INotifyPropertyChanged. When you bind a DataGridView to a DataTable, it has this cool little feature - it will not call DataTable.Rows.Add until after you leave the DataGridView row. This is cool because it lets your user edit the record as much as needed to get it into a valid state before actually adding it to the DataTable.
6
3219
by: Miro | last post by:
Sorry for the cross post. I am stuck. I have a datagridview for poker rounds. Basically there are 3 columns in this datagridview. "Round" "SmallBlind" "BigBlind" I have an issue when I tab through the new row being added. It does not 'Add' that row, nor setup the 'next blank add row' so I can continue to tab
0
9595
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9432
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10232
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8891
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7420
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3974
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.