We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

General questions

I am evaluating Essential Grid and I can't easily find out how to do the following things. 1. Set a minimum and maximum value for a cell. If the min is 10 and max is 20, if the user types in the user will get an error. 2. If I set CellValueType = typeof(double) it will prevent non-numeric entries on validation. How can I override the error message from "asdf is not a valid value for Double" to "asdf is not a number, please enter a number". 3. In the case of #2 above (i.e. the user has typed in a non-numeric value into a cell value that is double. I would like the user to be able to press "Cancel", however, the with a text value in the cell the Cancel button doensn't receive the click. 4. If I sent a cell to NumericUpDown, how can I then prevent the user from typing a value in that cell. In other words, I want the cell value to change only by using the NumericUpDown. Finally, a comment. The cell based nature of this grid makes it much easier to work with than anything else I have used. Kudos to the development team. I would like to agree with the other user who suggested the "Export to Excel" feature. In general any automated export to CSV, Tab Delimited, Excel, XML, etc. would only increase the value of the grid. Thank you.

2 Replies

AD Administrator Syncfusion Team February 3, 2003 10:04 PM UTC

1) Take a look at the Grid/Samples/Quick Start/TextFormat sample. Rows 11 and 12 there have validation implemented. 2) You can handle the CurrentCellValidating event and test the value there, cancelling th eevent and setting the message if necessary.
 
private void gridControl1_CurrentCellValidating(object sender, CancelEventArgs e)
{
	GridCurrentCell cc = this.gridControl1.CurrentCell;
	if( this.gridControl1[cc.RowIndex, cc.ColIndex].CellValueType == typeof(double))
	{
		string s = cc.Renderer.ControlText;
		try
		{
			double d = double.Parse(s);
		}
		catch
		{
			cc.ErrorMessage = "bad value";
			e.Cancel = true;
		}
	}
}
3) On your cancel button, try setting its CausesValidation property to false. 4) At the grid level, you could handle CurrrentCellKeyPress.
private void gridControl1_CurrentCellKeyPress(object sender, KeyPressEventArgs e)
{
	GridCurrentCell cc = this.gridControl1.CurrentCell;
	if(this.gridControl1[cc.RowIndex, cc.ColIndex].CellType == "NumericUpDown")
	{
		e.Handled = true;
	}
}
Currently, you can save CSV and TSV files. Future releases will support XLS and XML.
//save text
private void button3_Click(object sender, System.EventArgs e)
{
	this.gridControl1.Model.TextDataExchange.ExportTabDelim = ",";

	string outPut;
	int nRows, nCols;
	GridRangeInfoList rangeInfoList = new GridRangeInfoList();
	rangeInfoList.Add(GridRangeInfo.Cells(1, 1, this.gridControl1.RowCount, this.gridControl1.ColCount));
	bool b = this.gridControl1.Model.TextDataExchange.CopyTextToBuffer(out outPut, rangeInfoList, out nRows, out nCols);

	if(b)
	{
		StreamWriter writer = new StreamWriter("test.csv");
		writer.Write(outPut);
		writer.Close();
	}
}


TH Thor February 4, 2003 03:35 PM UTC

Thank you. > 1) Take a look at the Grid/Samples/Quick Start/TextFormat sample. Rows 11 and 12 there have validation implemented. > > 2) You can handle the CurrentCellValidating event and test the value there, cancelling th eevent and setting the message if necessary. >
 
> private void gridControl1_CurrentCellValidating(object sender, CancelEventArgs e)
> {
> 	GridCurrentCell cc = this.gridControl1.CurrentCell;
> 	if( this.gridControl1[cc.RowIndex, cc.ColIndex].CellValueType == typeof(double))
> 	{
> 		string s = cc.Renderer.ControlText;
> 		try
> 		{
> 			double d = double.Parse(s);
> 		}
> 		catch
> 		{
> 			cc.ErrorMessage = "bad value";
> 			e.Cancel = true;
> 		}
> 	}
> }
> 
> > 3) On your cancel button, try setting its CausesValidation property to false. > > 4) At the grid level, you could handle CurrrentCellKeyPress. >
> private void gridControl1_CurrentCellKeyPress(object sender, KeyPressEventArgs e)
> {
> 	GridCurrentCell cc = this.gridControl1.CurrentCell;
> 	if(this.gridControl1[cc.RowIndex, cc.ColIndex].CellType == "NumericUpDown")
> 	{
> 		e.Handled = true;
> 	}
> }
> 
> > > Currently, you can save CSV and TSV files. Future releases will support XLS and XML. > >
> //save text
> private void button3_Click(object sender, System.EventArgs e)
> {
> 	this.gridControl1.Model.TextDataExchange.ExportTabDelim = ",";
> 
> 	string outPut;
> 	int nRows, nCols;
> 	GridRangeInfoList rangeInfoList = new GridRangeInfoList();
> 	rangeInfoList.Add(GridRangeInfo.Cells(1, 1, this.gridControl1.RowCount, this.gridControl1.ColCount));
> 	bool b = this.gridControl1.Model.TextDataExchange.CopyTextToBuffer(out outPut, rangeInfoList, out nRows, out nCols);
> 
> 	if(b)
> 	{
> 		StreamWriter writer = new StreamWriter("test.csv");
> 		writer.Write(outPut);
> 		writer.Close();
> 	}
> }
> 

Loader.
Live Chat Icon For mobile
Up arrow icon