DataGrid
-
: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 -
: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 NguyenI 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.. }