473,761 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom Entity Databinding: Track deleted items?

12 New Member
Please help me with this databinding scenario:

Suppose I have a "Person" class, and that users populate Person objects in a BindingList collection through a datagridview. Users save the Person objects to the database when they click the save button.

When the user starts the app, a person datagridview is populated with Person objects in the BindingList. The user subsequenly deletes one of the rows in the table, deletes the Person object. How can I know which objects to delete in the underlying database when the user clicks the save button, since the object has been removed from the BindingList collection?

Thanks.
May 31 '07 #1
3 2169
nateraaaa
663 Recognized Expert Contributor
You will need to use a DataValueField when you Bind the data initially. Then when the user selects an item in the drop down list and clicks the button the item selected will have a specific value. This value should be the unique identifier for a row in your database table. You can then pass this identifier to your delete proc and delete the item that has this unique value. You will then need to rebind your data so that the drop down list will not contain the deleted item. Here is the code

Expand|Select|Wrap|Line Numbers
  1. DataView view = new DataView[ds.Tables[0]);
  2. ddlList.DataTextField = "columntext"; //This will be the column that holds the text to display in your drop down list
  3. ddlList.DataValueField = "uniqueid"; //This will be the column that contains the unique identifier for every row in your database table.
  4. ddlList.DataBind();
  5.  
  6. private void btnDelete_Click(object sender, System.EventArgs e)
  7. {
  8.   //Call the same code above after you call your Delete proc in this method. This will get the newest version of data to display in the drop down list after the delete has occurred.
  9. }
  10.  
After posting this code I realized that this will help you delete an item from a drop down list but you needed code to delete a row from a datagridview. My mistake.

Nathan
May 31 '07 #2
jimmarq
12 New Member
Your method would work for any databound control, really. Your solution is basically to update the database as soon as the control is updated. Ideally, I would have the user trigger the database update (e.g. by using a save button). Maybe I'm try to work the issue too hard.

Thanks for the response.
May 31 '07 #3
Frinavale
9,735 Recognized Expert Moderator Expert
Your method would work for any databound control, really. Your solution is basically to update the database as soon as the control is updated. Ideally, I would have the user trigger the database update (e.g. by using a save button). Maybe I'm try to work the issue too hard.

Thanks for the response.
Well instead of updating the same instant that the user deletes the Person...you could store the ID into an array and then go through and delete all the Persons matching the IDs during the "Save" button click.
Jun 1 '07 #4

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

Similar topics

3
1884
by: Cary Linkfield | last post by:
I have created a custom class inheriting CollectionBase and implementing IBindingList. I am binding the list to a datagrid. I would like to have a property on the class that works like the RowState of a DataRow that can tell the datagrid not to display the item anymore after it is marked for deletion by the user. I have a property on the class that indicates whether the item is Added, Unchanged, Modified or Deleted. I would like to...
3
12867
by: jamie_m_ | last post by:
I have a custom collection ... clFile that INHERITS from NameObjectCollectionBase the problem is, when I try to create an xmlserializer instance i get an error You must implement a default accessor on brWAP.clFile because it inherits from ICollectio I must be having a thick day because I dont have a clue what the error message means. (I have written a defaut property called ITEM in the clFile class 'Classes to abstract a FILE entity...
1
1647
by: glenn | last post by:
I have written as a test a customer class that has all the necessary field handling and formatting routines in it that I need. I have dataaccess class that controls reading and writing the class into the database. However, I am now getting to the user interface layer and a little confused as to where to head next. What I would like to do is somehow attach my class to a dataset or something that would make it easy to read and write data...
4
4210
by: dtblankenship | last post by:
Hello everyone, I know this question has been asked many times in the forums, and after spending a few days reading, I am still confused as to the answer. I have a ListBox (lstBox), SqlConnection (sqlConnection), SqlDataAdapter (daLookupData), SqlDataAdapter (daData), DataSet (dsLookupData), and DataSet (dsData), all created via the IDE during design-time. Here is the design of my simple tables: (An example since I can't post my...
7
3342
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid, theres a requirement to show a drop down menu list (this is a control I downloaded online) in one of the columns. For the purposes of this question, Ive implemented the drop down menu as a drop down list instead. Ive got all this working at this...
2
3309
by: S. Justin Gengo | last post by:
Hi, I've created a component that allows me to store database information for various types of databases my company uses. It uses a collection for each type of database. Everything is working perfectly except when the component is deleted from the page. Here are the details. I add the component to the page from the toolbox and then add items using the collection editor. I can delete those items from the collection using the collection...
1
15033
by: Mike Hofer | last post by:
I am trying to do something a little nonstandard, and am having some difficulty determining (a) if it can be done and (b) if so, how to do it. What I want to do is fill a dropdown combobox with data from a collection. Then, I want to bind that list to a member of a custom class. (Don't ask why, just trust me on that one. <gr>). What I'm doing now is binding the combo box to a collection, as follows: Dim items As ArmorTypeCollection =...
1
1370
by: jamie_m_ | last post by:
I have a custom collection ... clFile that INHERITS from NameObjectCollectionBase the problem is, when I try to create an xmlserializer instance i get an error You must implement a default accessor on brWAP.clFile because it inherits from ICollectio I must be having a thick day because I dont have a clue what the error message means. (I have written a defaut property called ITEM in the clFile class
1
18885
by: Dave A | last post by:
Hi, I am struggling with two way databinding in WinForms and the DataGridView. I am binding to business object classes (rather than datatables). If I have a collection of these business objects that is the datasource of a DataBinding that is bound to a DataGridView (WinForms) then I was expecting that any change to the data would be reflected in the DataGridView (in other words I was expecting the 2 way databinding to actually...
0
9377
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
9989
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9925
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
8814
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...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5266
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
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3913
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
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.