locked
getting content of a cell of deleted row RRS feed

  • Question

  • Hello,

    I have DataGridView and I want when I delete column to be able to delete it from the database. Now I have one cell containing the primary key. I'm using the UserDeletedRow event.How do I get the deleted cell value? If not possible then what event do I use for this purpose?

    Thanks

    Friday, November 12, 2010 9:59 AM

Answers

  • before you delete the cell, you simply retrive the cell value like:

          int row = this.dataGridView1.CurrentCell.RowIndex;
          int column = this.dataGridView1.CurrentCell.ColumnIndex;
          string cellValue = this.dataGridView1[column, row].Value.ToString();
          //now you have the vlaue in the cellValue 
          //you can delete the column
    

    If this is not helpful, let me know, I will try to get some other solution,

    bye

    Mitja

    • Marked as answer by Barbi Rio Monday, November 15, 2010 8:07 AM
    Friday, November 12, 2010 6:49 PM

All replies

  • before you delete the cell, you simply retrive the cell value like:

          int row = this.dataGridView1.CurrentCell.RowIndex;
          int column = this.dataGridView1.CurrentCell.ColumnIndex;
          string cellValue = this.dataGridView1[column, row].Value.ToString();
          //now you have the vlaue in the cellValue 
          //you can delete the column
    

    If this is not helpful, let me know, I will try to get some other solution,

    bye

    Mitja

    • Marked as answer by Barbi Rio Monday, November 15, 2010 8:07 AM
    Friday, November 12, 2010 6:49 PM
  • Dear Mitja,

    What event do I work with then to catch before deleting a row? I was searching for RowDeleting or UserRowDeleting or anything similar but i didnt manage to find. Getting the cell value it is easy if the cell is not deleted yet but how do i catch that event? how do I get the cell before deleting?

    Thanks

    Monday, November 15, 2010 4:44 AM
  • Are you using data binding? dont use the grid, use your data collection and a binding source


    gimme some slamming techno!!!!
    Monday, November 15, 2010 5:10 AM
  • Dear Blair Allen Stark

    Can you be more specific please? And how would binding source help me? Can you please post an example?

    Thanks

    Monday, November 15, 2010 5:27 AM
  • well. .  first. .  what are you binding to? DataTable?

    http://msdn.microsoft.com/en-us/library/system.data.datatable.rowdeleted.aspx

    DataSet has GetChanges

    http://msdn.microsoft.com/en-us/library/0f8054fy.aspx

    BiindingSource has ListChangedEvent

    http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.listchanged.aspx

    An implementation of BindingList?

    you can override RemoveItem and get the item by index and then call base.removeitem

    remember. .  the grid is just the presentation - logically operate off of your bound model. it will make your life easier


    gimme some slamming techno!!!!
    Monday, November 15, 2010 5:58 AM
  • Thank you all, I have found the UserRowDeleting and everything works fine
    Monday, November 15, 2010 8:08 AM
  • the thing is...

     

    if you are databinding, you operate on the collection.  use the currency infrastructure to manage items. remove an item from the data source, the ui updates. you dont need vaulues from the grid, you have the itme you removed.


    gimme some slamming techno!!!!
    Tuesday, November 16, 2010 4:11 AM