473,394 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Help with DataGrid and MemberwiseClone() Visual C++ using .NET

I am currently using Visual Studio 2008 Pro edition programming a windows form application using Visual C++.

I am using datagrids, the user can populate fields with data. I am not using datasets because the information doesn't have to remain once the app has closed. When the user selects a row and deletes it with the "Delete" key on the keyboard, I want to trigger an event. I got it to this point but now I am having a problem because I want to know the contents of the fields that were deleted. So I am trying this e->MemberwiseClone() to get the contents of the cells and save into "row" so that I can gain access to the cells. But unfortunately I get this error:

error C3767: 'System::Object::MemberwiseClone': candidate function(s) not accessible

MemberwiseClone() is under protected, so I tried the #pragma make_public but I also got an error with that, although I'm not sure if I used that correctly or not.

My ultimate goal is to find out the contents of the cells that were deleted. I don't know if I am taking the right approach but that is my goal. I am open to any suggestions and would greatly appreciate them. Thanks in advance.

Expand|Select|Wrap|Line Numbers
  1. private: System::Void dataGridView1_RowsRemoved(System::Object^  sender, System::Windows::Forms::DataGridViewRowsRemovedEventArgs^  e)
  2. {
  3.      //to verify that the deletion is working correctly
  4.      MessageBox::Show("row " + e->RowIndex.ToString() + " has been removed");
  5.  
  6.      DataGridViewRow row = (DataGridViewRow) e->MemberwiseClone();
  7. }
  8.  
  9. }
  10.  
Dec 11 '08 #1
2 3561
Banfa
9,065 Expert Mod 8TB
MemberwiseClone is protected, it must be called within the context of the class.

#pragma make_public is about altering the accessibility of native type members (C++ structs and classes) when you are unable to change the headers they are defined in.

I see no way in which casting DataGridViewRowsRemovedEventArgs to DataGridViewRow can be valid.
Dec 11 '08 #2
Thanks Banfa for the information, I looked into it. This is the solution I found with help.

This is the final version, I actually needed one specific cell (column index 0) from the row that was being deleted, so hence this code works great.

Expand|Select|Wrap|Line Numbers
  1.  
  2. //for people viewing this thread, you need to add an event handler in your Windows Form Designer generated code portion. Without it, this won't work.
  3. //Shown here:
  4. this->dataGridView1->UserDeletingRow += gcnew System::Windows::Forms::DataGridViewRowCancelEventHandler(this, &Form1::dataGridView1_UserDeletingRow);
  5.  
  6.  
  7.  
  8. private: System::Void dataGridView1_UserDeletingRow(System::Object^  sender, System::Windows::Forms::DataGridViewRowCancelEventArgs ^  e)
  9.  {    
  10.       //specifying a colum index of 0 of the row being deleted         
  11.       MessageBox::Show(e->Row->Cells[0]->Value->ToString());
  12.       //passing that value from column 0 and row being deleted to be processed elsewhere      
  13.       do_something(e->Row->Cells[0]->Value->ToString());
  14. }
  15.  
  16.  
Dec 11 '08 #3

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

Similar topics

0
by: Patrick | last post by:
I'm working on a contact management application, and need a hand with one aspect... Here's what I want to create: ------------------------------------ A form split into two parts. There is a...
1
by: lewindha | last post by:
Hey guys I'm trying to populate a drop down list with values from a db table. When I view the page, the drop list is empty. Here is the code: private void populateClients() { string...
6
by: Anders Borum | last post by:
Hello! I accidentally posted this as a reply to another posting. It is a seperate posting - sorry :-) I am programming a cloning service (which is essential to the framework), and am...
6
by: Das | last post by:
Hi everyone, I'm using datagrid control to display the data. I want to hide column to be displayed into the data grid. I'm using the code as given below: Method given below is used to bind the...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
2
by: Daniel Walzenbach | last post by:
Hi, I created an ASP.NET Datagrid where a single row can be selected by clicking anywhere on the row (according to...
2
by: thebison | last post by:
Hi, As a relative newbie to SQL Server/ASP.NET I'm hoping someone here can help with my problem. I'm developing a timesheet application in ASP.NET C# using Visual Studio 2003 with a database...
53
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code,...
2
by: bmerlover | last post by:
I am currently using Visual Studio 2008 Pro edition programming a windows form application using Visual C++. I am using datagrids, the user can populate fields with data. I am not using datasets...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.