473,766 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

adding data using DataGridView

What is the best way to add data using a DataGridView in a multi-tier
application (data entry is handled in a data access layer using stored
procedures)?

Thanks
Bill
Jan 10 '07 #1
7 7342
You can make a class that is a IBindingList(of object) where
object is your class and then bind that class to the DataGridView.
Not sure about the updates, though, as I haven't done that (yet).
You probably have to handle them yourself.

Robin S.

"BillE" <be****@datamti .comwrote in message
news:eE******** ******@TK2MSFTN GP02.phx.gbl...
What is the best way to add data using a DataGridView in a multi-tier
application (data entry is handled in a data access layer using stored
procedures)?

Thanks
Bill


Jan 10 '07 #2
How would I add a new record with that?

"RobinS" <Ro****@NoSpam. yah.nonewrote in message
news:V9******** *************** *******@comcast .com...
You can make a class that is a IBindingList(of object) where
object is your class and then bind that class to the DataGridView.
Not sure about the updates, though, as I haven't done that (yet).
You probably have to handle them yourself.

Robin S.

"BillE" <be****@datamti .comwrote in message
news:eE******** ******@TK2MSFTN GP02.phx.gbl...
>What is the best way to add data using a DataGridView in a multi-tier
application (data entry is handled in a data access layer using stored
procedures)?

Thanks
Bill



Jan 10 '07 #3
Well, therein lies the rub. I have to figure out how to do this
in the next few days, too.

I'll probably try adding records to the grid and see what it
does to my business layer. It will probably raise an event
that I can handle and create a new instance of my class and
add it to the List. Or try changing records -- same thing,
I'll check and see if it propagates back to my BO.

And if I get frustrated and just want to get it done, I'll
pop up a form on top with all the fields on it, and let them
add/change/delete it from there, at which point I will
add, change, or delete the record from the List. Since the
grid is bound to the List, it will update automatically.

That's my theory. Do you have any brilliant ideas?

Robin S.
--------------------------------
"BillE" <be****@datamti .comwrote in message
news:O1******** ******@TK2MSFTN GP02.phx.gbl...
How would I add a new record with that?

"RobinS" <Ro****@NoSpam. yah.nonewrote in message
news:V9******** *************** *******@comcast .com...
>You can make a class that is a IBindingList(of object) where
object is your class and then bind that class to the DataGridView.
Not sure about the updates, though, as I haven't done that (yet).
You probably have to handle them yourself.

Robin S.

"BillE" <be****@datamti .comwrote in message
news:eE******* *******@TK2MSFT NGP02.phx.gbl.. .
>>What is the best way to add data using a DataGridView in a
multi-tier application (data entry is handled in a data access layer
using stored procedures)?

Thanks
Bill




Jan 10 '07 #4
I thought I might post the question on a newsgroup!
"RobinS" <Ro****@NoSpam. yah.nonewrote in message
news:gK******** *************** *******@comcast .com...
Well, therein lies the rub. I have to figure out how to do this
in the next few days, too.

I'll probably try adding records to the grid and see what it
does to my business layer. It will probably raise an event
that I can handle and create a new instance of my class and
add it to the List. Or try changing records -- same thing,
I'll check and see if it propagates back to my BO.

And if I get frustrated and just want to get it done, I'll
pop up a form on top with all the fields on it, and let them
add/change/delete it from there, at which point I will
add, change, or delete the record from the List. Since the
grid is bound to the List, it will update automatically.

That's my theory. Do you have any brilliant ideas?

Robin S.
--------------------------------
"BillE" <be****@datamti .comwrote in message
news:O1******** ******@TK2MSFTN GP02.phx.gbl...
>How would I add a new record with that?

"RobinS" <Ro****@NoSpam. yah.nonewrote in message
news:V9******* *************** ********@comcas t.com...
>>You can make a class that is a IBindingList(of object) where
object is your class and then bind that class to the DataGridView.
Not sure about the updates, though, as I haven't done that (yet).
You probably have to handle them yourself.

Robin S.

"BillE" <be****@datamti .comwrote in message
news:eE****** ********@TK2MSF TNGP02.phx.gbl. ..
What is the best way to add data using a DataGridView in a multi-tier
applicatio n (data entry is handled in a data access layer using stored
procedures )?

Thanks
Bill




Jan 11 '07 #5
I noticed that if I bind the dgv to a BindingSource control, when I type in
a new record in the dgv the 'AddingNew' event of the BindingSource fires.
The problem is that it fires when I first enter the new row before entering
new data, as well as when I leave the new row after entering new data, so it
is necessary to find some way to distinguish between the two before saving
the record. It seems clumsy to toggle a flag or something, there must be a
neat way to do this.

"RobinS" <Ro****@NoSpam. yah.nonewrote in message
news:gK******** *************** *******@comcast .com...
Well, therein lies the rub. I have to figure out how to do this
in the next few days, too.

I'll probably try adding records to the grid and see what it
does to my business layer. It will probably raise an event
that I can handle and create a new instance of my class and
add it to the List. Or try changing records -- same thing,
I'll check and see if it propagates back to my BO.

And if I get frustrated and just want to get it done, I'll
pop up a form on top with all the fields on it, and let them
add/change/delete it from there, at which point I will
add, change, or delete the record from the List. Since the
grid is bound to the List, it will update automatically.

That's my theory. Do you have any brilliant ideas?

Robin S.
--------------------------------
"BillE" <be****@datamti .comwrote in message
news:O1******** ******@TK2MSFTN GP02.phx.gbl...
>How would I add a new record with that?

"RobinS" <Ro****@NoSpam. yah.nonewrote in message
news:V9******* *************** ********@comcas t.com...
>>You can make a class that is a IBindingList(of object) where
object is your class and then bind that class to the DataGridView.
Not sure about the updates, though, as I haven't done that (yet).
You probably have to handle them yourself.

Robin S.

"BillE" <be****@datamti .comwrote in message
news:eE****** ********@TK2MSF TNGP02.phx.gbl. ..
What is the best way to add data using a DataGridView in a multi-tier
applicatio n (data entry is handled in a data access layer using stored
procedures )?

Thanks
Bill




Jan 11 '07 #6
In my class definition, I'm keeping a property for RowState. So I have
a theory that I can use that to determine whether an entry is deleted,
added, or updated, as long as I can figure out how to capture those
events.

I created my class last night, and the list of it inherits BindingList.
I created a data source (type=Object) using the wizard and dragged it
onto my form to create and bind my DGV. Then I have in my form_load
the load of the list (it runs the Create method).

The add and save buttons on the created binding list are greyed out,
but the delete button is not, so I whacked it, and sure enough one
of my rows disappeared.

Now, this is not cascading down to the underlying data source because
I haven't run EndEdit. Tomorrow I'll give that a try. (Going to MacWorld
today!).

I'm also going to my local .Net users group meeting tonight, and will
ask there if anybody has done this and see if I can get some free
advice. I'll report back.

This ought to be entertaining...
Robin S.
----------------------------------------
"BillE" <be****@datamti .comwrote in message
news:uR******** ******@TK2MSFTN GP02.phx.gbl...
>I noticed that if I bind the dgv to a BindingSource control, when I
type in a new record in the dgv the 'AddingNew' event of the
BindingSourc e fires. The problem is that it fires when I first enter
the new row before entering new data, as well as when I leave the new
row after entering new data, so it is necessary to find some way to
distinguish between the two before saving the record. It seems clumsy
to toggle a flag or something, there must be a neat way to do this.

"RobinS" <Ro****@NoSpam. yah.nonewrote in message
news:gK******** *************** *******@comcast .com...
>Well, therein lies the rub. I have to figure out how to do this
in the next few days, too.

I'll probably try adding records to the grid and see what it
does to my business layer. It will probably raise an event
that I can handle and create a new instance of my class and
add it to the List. Or try changing records -- same thing,
I'll check and see if it propagates back to my BO.

And if I get frustrated and just want to get it done, I'll
pop up a form on top with all the fields on it, and let them
add/change/delete it from there, at which point I will
add, change, or delete the record from the List. Since the
grid is bound to the List, it will update automatically.

That's my theory. Do you have any brilliant ideas?

Robin S.
--------------------------------
"BillE" <be****@datamti .comwrote in message
news:O1******* *******@TK2MSFT NGP02.phx.gbl.. .
>>How would I add a new record with that?

"RobinS" <Ro****@NoSpam. yah.nonewrote in message
news:V9****** *************** *********@comca st.com...
You can make a class that is a IBindingList(of object) where
object is your class and then bind that class to the DataGridView.
Not sure about the updates, though, as I haven't done that (yet).
You probably have to handle them yourself.

Robin S.

"BillE" <be****@datamti .comwrote in message
news:eE***** *********@TK2MS FTNGP02.phx.gbl ...
What is the best way to add data using a DataGridView in a
multi-tier application (data entry is handled in a data access
layer using stored procedures)?
>
Thanks
Bill
>
>




Jan 11 '07 #7
Thanks!

"RobinS" <Ro****@NoSpam. yah.nonewrote in message
news:SP******** *************** *******@comcast .com...
In my class definition, I'm keeping a property for RowState. So I have
a theory that I can use that to determine whether an entry is deleted,
added, or updated, as long as I can figure out how to capture those
events.

I created my class last night, and the list of it inherits BindingList.
I created a data source (type=Object) using the wizard and dragged it
onto my form to create and bind my DGV. Then I have in my form_load
the load of the list (it runs the Create method).

The add and save buttons on the created binding list are greyed out,
but the delete button is not, so I whacked it, and sure enough one
of my rows disappeared.

Now, this is not cascading down to the underlying data source because
I haven't run EndEdit. Tomorrow I'll give that a try. (Going to MacWorld
today!).

I'm also going to my local .Net users group meeting tonight, and will
ask there if anybody has done this and see if I can get some free
advice. I'll report back.

This ought to be entertaining...
Robin S.
----------------------------------------
"BillE" <be****@datamti .comwrote in message
news:uR******** ******@TK2MSFTN GP02.phx.gbl...
>>I noticed that if I bind the dgv to a BindingSource control, when I type
in a new record in the dgv the 'AddingNew' event of the BindingSource
fires. The problem is that it fires when I first enter the new row before
entering new data, as well as when I leave the new row after entering new
data, so it is necessary to find some way to distinguish between the two
before saving the record. It seems clumsy to toggle a flag or something,
there must be a neat way to do this.

"RobinS" <Ro****@NoSpam. yah.nonewrote in message
news:gK******* *************** ********@comcas t.com...
>>Well, therein lies the rub. I have to figure out how to do this
in the next few days, too.

I'll probably try adding records to the grid and see what it
does to my business layer. It will probably raise an event
that I can handle and create a new instance of my class and
add it to the List. Or try changing records -- same thing,
I'll check and see if it propagates back to my BO.

And if I get frustrated and just want to get it done, I'll
pop up a form on top with all the fields on it, and let them
add/change/delete it from there, at which point I will
add, change, or delete the record from the List. Since the
grid is bound to the List, it will update automatically.

That's my theory. Do you have any brilliant ideas?

Robin S.
--------------------------------
"BillE" <be****@datamti .comwrote in message
news:O1****** ********@TK2MSF TNGP02.phx.gbl. ..
How would I add a new record with that?

"RobinS" <Ro****@NoSpam. yah.nonewrote in message
news:V9***** *************** **********@comc ast.com...
You can make a class that is a IBindingList(of object) where
object is your class and then bind that class to the DataGridView.
Not sure about the updates, though, as I haven't done that (yet).
You probably have to handle them yourself.
>
Robin S.
>
"BillE" <be****@datamti .comwrote in message
news:eE**** **********@TK2M SFTNGP02.phx.gb l...
>What is the best way to add data using a DataGridView in a multi-tier
>applicatio n (data entry is handled in a data access layer using
>stored procedures)?
>>
>Thanks
>Bill
>>
>>
>
>




Jan 11 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
6416
by: dbuchanan | last post by:
Hello, Is this a bug? Is there some kind of work around? I want to add default values for a few columns in my datagridview I found the "DefaultValuesNeeded" event for the datagridview I gave it a try using the example given in
4
1817
by: Ian Semmel | last post by:
I have a DataGridView bound to a DataTable which is keyed on an Identity. Now I want users to be able to fill in the table just by enetering data and tab between fields and across row boundaries. What I am having trouble with is deciding when to update the table and I keep on getting exceptions (like DbNull). Do you have to do an update at the end of each row ?
2
5019
by: Ivan | last post by:
I have a class Foo which have two property. I have a thread that do some process and update class Foo int B. I have a datagridview on main form. this datagridview data source to this class Foo and column A binds to string A and column B binds to int B. When i start two threads, the datagridview able to show two rows and updated int B at run time. How? public class Foo { public Foo()
2
8722
by: Rick Shaw | last post by:
Hi, I have a problem with the datagridview not refreshed when the application first appear on the screen. The datagridview display data from a table in the dataset. At the same time, I've added checkbox columns that are not bounded the table. This datagridview is located in the tab (2nd). I thought I mention that since that might be part of the problem (?). When the applications start, it will need some parameter criteria selection...
2
5791
by: JDeats | last post by:
Does the Microsoft DataGridView control support multiple bands (i.e. expanding rows with embedded grids). If not, can anyone recommend a good third-party solution for someone needing to manually build out a multi-band grid without a fixed data source. The Infragistics controls seem to be based entirely around a data source. I really don't want the control to try and "help me" in this way. I just want maximum flexibility at run-time. The...
3
35755
by: SimonHeffer | last post by:
I've added a DataGridView and added some columns in the designer, now I want to add some rows with data applied via column name. Having done some web trawling I've ended up with this: private void AddRow(string thing,string thingdesc) { DataGridViewRow row = new DataGridViewRow(); row.CreateCells(MyGrid); // #1 row.Cells.Value = "Add"; // #2 this makes it work MyGrid.Rows.Add(row); ...
4
9632
by: =?Utf-8?B?VGVycnk=?= | last post by:
I have a DataGridView bound to a collection of Custom Objects. I have enabled adding new rows, but since my object does not have a public constructor (it uses a factory method), I get an error when I attempt to enter the new row. My guess is that I need to override some method so that I can create the object for the grid. But for the life of me, and I can't find it. Can someone point me in the right direction? -- Terry
4
4604
by: Dom | last post by:
I'm just playing around, to confirm my mental picture of what is happening in CSharp. Looks like I got the wrong mental picture, because I thought this would work. I created a class, MyDGVR, which extends the DataGridViewRow, and just added a little functionality by adding a property called NewProperty. Then I did the following: MyDGVR r = new MyDGVW (1, 2, 3); DataGridView.Rows.Add (r);
3
9689
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.
0
9568
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
10168
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...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9837
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...
1
7381
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
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
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
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.