Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ColumnChanging event on Dataset

ColumnChanging event on Dataset

Scheduled Pinned Locked Moved C#
help
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    C Coder67
    wrote on last edited by
    #1

    Hi all, I have a ColumnChanging event attached to a dataset to perform validations. For some reason unknown to me, the event does not get fired when the user presses the 'tab' key with a null cell. I am trying to make sure that no cell is null. When no value is entered in a cell, and the column is changed, I want the ColumnChanging event to capture it and throw a messagebox to the user. Please help. Here is what I have --> private void Division_ColumnChanging(object sender, System.Data.DataColumnChangeEventArgs e) { ... .. . if ( (e.Column.ColumnName.Equals("Div_Code")) || (e.Column.ColumnName.Equals("Div_Name")) ) { if(e.ProposedValue.ToString().Length == 0) { MessageBox.Show("Column " + cs.HeaderText + " cannot be null.", "SPIRIT2 - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); dataGrid1.CurrentCell = (DataGridCell) sender; } } ... .. . }

    L 1 Reply Last reply
    0
    • C C Coder67

      Hi all, I have a ColumnChanging event attached to a dataset to perform validations. For some reason unknown to me, the event does not get fired when the user presses the 'tab' key with a null cell. I am trying to make sure that no cell is null. When no value is entered in a cell, and the column is changed, I want the ColumnChanging event to capture it and throw a messagebox to the user. Please help. Here is what I have --> private void Division_ColumnChanging(object sender, System.Data.DataColumnChangeEventArgs e) { ... .. . if ( (e.Column.ColumnName.Equals("Div_Code")) || (e.Column.ColumnName.Equals("Div_Name")) ) { if(e.ProposedValue.ToString().Length == 0) { MessageBox.Show("Column " + cs.HeaderText + " cannot be null.", "SPIRIT2 - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); dataGrid1.CurrentCell = (DataGridCell) sender; } } ... .. . }

      L Offline
      L Offline
      link_79
      wrote on last edited by
      #2

      Hi, Typically in the empty column of a table, the value "(null)" is entered by default(for a data grid atleast) and that is probably why the null case is not being detected. You will probably need to put in a break point to see if the value being returned is indeeed "NULL" instead of "" like you expect. I haven't tested this myslef so I could be way off. Hope this helps.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups