Results 1 to 2 of 2

Thread: DataGrid KeyPress Event

  1. #1

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    DataGrid KeyPress Event

    Hi all,

    I need to work with keypress or keydown event of data grid. I have an editable datagrid, and when user enters data in the datagrid, I want to display total accordingly. For this purpose, I wrote code in Keypress event but event is not firing. Moreover, I tried KeyDown but its also not firing.

    Any ideas ??

    Thanks

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Re: DataGrid KeyPress Event

    You could use the CurrentCellChanged event, i.e.
    Code:
          private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
          {
             int index = dataGrid1.CurrentCell.ColumnNumber;
    
             decimal total = 0;
             foreach(DataRow row in ((DataTable)dataGrid1.DataSource).Rows)
                if( row[index] != DBNull.Value ) 
                   total += Convert.ToDecimal(row[index]);
    
             label1.Text = string.Format("Total for this column in {0}", total);
          }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width