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. DataGrid

DataGrid

Scheduled Pinned Locked Moved C#
helpcsstutorial
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.
  • D Offline
    D Offline
    DucLinh
    wrote on last edited by
    #1

    :doh:i do not know how to catch error in data grid cell. this is the code i writed: private void ColumnChangingHandler(object sender,DataColumnChangeEventArgs args) { switch(args.Column.ColumnName) { case "accID": { DataGridCell oldCell= new DataGridCell(); string values=args.ProposedValue.ToString(); if(!this.IsNumber(values)) { MessageBox.Show("value must be number"); } else if(!IsLengh(values)) { MessageBox.Show("It must be 4 characters"); } break; } .............................. after catch error i want to return the focus on error cell. Please help me as possible as you can. Thanks. Mr Duc Linh Nguyen

    B 1 Reply Last reply
    0
    • D DucLinh

      :doh:i do not know how to catch error in data grid cell. this is the code i writed: private void ColumnChangingHandler(object sender,DataColumnChangeEventArgs args) { switch(args.Column.ColumnName) { case "accID": { DataGridCell oldCell= new DataGridCell(); string values=args.ProposedValue.ToString(); if(!this.IsNumber(values)) { MessageBox.Show("value must be number"); } else if(!IsLengh(values)) { MessageBox.Show("It must be 4 characters"); } break; } .............................. after catch error i want to return the focus on error cell. Please help me as possible as you can. Thanks. Mr Duc Linh Nguyen

      B Offline
      B Offline
      benqazou
      wrote on last edited by
      #2

      I am not sure what you need to do, but I think this can help you.. In the constructor of the form (for example), you add something like this : DataGridTextBoxColumn _datagridtextBox = (DataGridTextBoxColumn)YourDataGrid.TableStyles[0].GridColumnStyles[**X**]; _datagridtextBox.TextBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(Execute_This); where X is the index of the column that is supposed to have only numbers of 4 characters.. You will also need to write something like this : private void Execute_This(object sender, System.Windows.Forms.KeyPressEventArgs e) { TextBox tBox = (textBox) sender; //tBox.Text is the text that has been already written by the user.. //e.KeyChar is the chararacter corresponding to the character that the user has just written..You just make tests.. }

      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