Validating in a DataGrid
I use a TextInput ItemEditor in a Datagrid. How do I make
sure the user only inputs numeric input? I can use restrict to get
only integers, but what if I want real numbers with two decimal
places?
A simple solution would be to use a Number Validator as seen
here:
http://livedocs.adobe.com/flex/3/html/help.html?content=validators_1.html
:S
Similar Messages
-
Validation on a Datagrid Column
Hi,
I have a Datagrid with three columns, out of which two columns are editable. I want to apply string validator on one of the editable column. How can I do this?You can have a custom ItemRenderer for that column which has a Validator built in. This has been covered in the docs. See this: http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Live Docs_Book_Parts&file=celleditor_073_17.html
-
Validation on ItemEditEnd of Datagrid
I have done validations on ItemEditEnd of datagrid but on
focusout its showinf two alerts. Can anyone specify the
reason?Can we see some simplified code?
-
Hey guys i have a web app that basically has a browse button and when the user clicks the button it prompts for a file on their PC and loads a datagrid.
My question is rather simple. How do I validate the date columns on datagrid so that it should be formatted like so 17-MAR-10 and not anything other then that. i have a done validation on datagrid with custom classes i built but i have no idea how to go about validating an specific formatt.
Any Help would be greatly appreciated.
Thanks
Migueltwo assumptions:
if you need to show the date in your format - then use itemrenderer or labelfunction.
if you need to show only the rows with that format, then filter the arraycollection - the data provider. -
Simple DataGrid validation Problem
hi friends
I am working on a application in which i m facing a problem.i have a datagrid having two column field one is simple datagrid column and in other datagrid column i render textinput as a component. there are only two row in my datagrid.so now i have to apply validation on that data grid.i mean if any textinput componet which is render in second column in data grid left blank and i click on save button then there should be validation Alert messg.
i am facing a problem on gettin id(instance) of that two rendered textinput component.Please help me out.
Thanks and Regards
Vineet OshoHi Vineet Osho,
You can try this...
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
>
<mx:Script>
<![CDATA[
import mx.utils.StringUtil;
import mx.collections.ArrayCollection;
import mx.controls.TextInput;
import mx.events.DataGridEvent;
import mx.controls.Alert;
public var arr:Array = [];
public var incrementer:int;
private function validateTextInputs():void
var strIndexes:String="";
var gridDP:ArrayCollection = dataGrid.dataProvider as ArrayCollection;
for(var i:int=0;i<gridDP.length;i++)
if(StringUtil.trim(gridDP.getItemAt(i).displayText) == "")
strIndexes += (i + 1) + ",";
if(strIndexes.length > 0)
strIndexes = strIndexes.substring(0,strIndexes.length-1);
Alert.show("The TextInputs " + strIndexes + " are empty.");
]]>
</mx:Script>
<mx:DataGrid id="dataGrid" horizontalCenter="0" verticalCenter="0" width="400" height="200">
<mx:columns>
<mx:DataGridColumn headerText="First" width="60" dataField="artist" editable="false"/>
<mx:DataGridColumn width = "60" headerText = "Premium %(e.g. Percentage as 100)" >
<mx:itemRenderer>
<mx:Component>
<mx:TextInput styleName="TextInputRight" focusOut="data.displayText=this.text;" width="100" text="{data.displayText}">
</mx:TextInput>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
<mx:dataProvider>
<mx:ArrayCollection>
<mx:Array>
<mx:Object title="Stairway to Heaven" artist="Led Zepplin" displayText=""/>
<mx:Object title="How to Save a Life" artist="Fray" displayText=""/>
</mx:Array>
</mx:ArrayCollection>
</mx:dataProvider>
</mx:DataGrid>
<mx:Button id="btn" label="click" x="527" y="450" click="validateTextInputs()" />
</mx:Application>
Thanks,
Bhasker -
Hi all,
I have an application with datagrid inline editing
functionality. I have a custom item renderer for all the columns
and i have to perform validations also on the user entered data.
The itemEditEnd function goes like this,
private function editCell(event:DataGridEvent ) : void
if( event.reason == DataGridEventReason.CANCELLED) {
return;
var oldValue:String =
event.currentTarget.editedItemRenderer.data[event.dataField];
var newValue:String =
TextInput(event.currentTarget.itemEditorInstance).text;
if(newValue == "") {
event.preventDefault();
TextInput(dg.itemEditorInstance).errorString ="Enter a valid
string.";
return;
typical ex from Adobe.
It works fine and shows the error string in the exact edited
text box inside Grid.
But Once i integrate wit the DB with DMS call and tried to
edit, the error message is shown at a random place, say on top of
the page.
please help me out to solve this.
thanks in advanceWorst forums ever! Nobody can help with the insertion of a
currencyvalidator in a datagrid itemeditor? -
Validation of user inputs when using ItemRenderers in DataGrid
Hi,
I have to show multiple editable columns in a DataGrid.
The columns may have different formats and datatypes e.g.
numbers, dates, string etc.
So I am using TextInput/DateField as a ItemRenderer inside
the DataGrid. I have also set the rendererIsEditor="true".
Now I want to apply validation to all these editable columns
depending on their datatypes.
I know I can do that by applying validators individually on
each column.
But is there a way I can use common validation for all the
columns that have a similar datatype or that have the same
renderer?You can use the itemEditEnd Event of the DataGrid for your
validation. Then you can use Actionscript to make sure what the
user enters is in the right format. Example:
<mx:Script>
<![CDATA[
import mx.events.DataGridEvent;
public function processEdit(event:DataGridEvent):void {
cellValue =
TextInput(event.currentTarget.itemEditorInstance).text; // the
entered text
cell = event.dataField; //the datafield attribute of the
column
// Determine if the new value is too long for nvarchar field
if(cell == 'WLNET' && cellValue.length > 35) {
cellValue = cellValue.substr(0,35); //shortening it for user
demonstrates expected length
TextInput(event.currentTarget.itemEditorInstance).text =
cellValue;
event.preventDefault(); // Prevent the user from removing
focus, and leave the cell editor open.
// Write a message to the errorString property.
// This message appears when the user mouses over the
editor.
TextInput(event.currentTarget.itemEditorInstance).errorString="Entered
text too long.";
return;
]]>
</mx:Script>
<mx:DataGrid id="enrolled_dg" editable="true"
itemEditEnd="processEdit(event);">
I learned part of this from the Flex documentation online:
Determining
the reason for an itemEditEnd event -
Validating user input in a datagrid column
Hi ,
I have 2 datagrid columns for users to enter data. I want to
restrict them only to enter numbers. I tried NumberValidator , that
does not work. Please help !! I am a newbee..
Thanks in advance..We created an itemEditor for our dataColumn that was a
mx:TextInput. Then we used the textInput event to capture keys as
they are typed. You get a TextEvent from that which you can cancel
if it something you don't want the user entering. We used regexs
for are validation here. I'm not sure if this is the best way to
handle this sort of thing, but it worked. -
Editing with a DataGrid and validating user input
Editing
with a DataGrid Tutorial
How to edit the information in a Flex 2 DataGrid directly,
without data binding TextInputs to it.
Uses a Remote Object, a CFC, and a Microsoft Access database
to demonstrate how.
Uses Actionscript to validate the data the user types into
the DataGrid.We created an itemEditor for our dataColumn that was a
mx:TextInput. Then we used the textInput event to capture keys as
they are typed. You get a TextEvent from that which you can cancel
if it something you don't want the user entering. We used regexs
for are validation here. I'm not sure if this is the best way to
handle this sort of thing, but it worked. -
Hi,
Is there any way to validate datagrid column or cell.
Please help
Thanks
Kumarquote:
Originally posted by:
peterent
Follow Tracy's advice, but also handle the itemEditEnd event.
In that event handler you can find if the data passed validation.
If it fails you can cancel the edit.
Look up itemEditEnd in the Flex 2 docs. -
DataGrid and Validation?
I'm having a hard time putting a CurrencyValidator inside of
a DataGrid. The breakpoints would indicate that the data binds
properly, but I get an unfortunately XML mess with big scrollbars
in the datagrid instead of what I'd expect.
Here's the GenericDollarFormatItemRenderer.mxml that
intuition built:
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="
http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridColumn;
public var dataField:String;
[Bindable]
private var dataString:String;
public function newInstance():*
return new GenericDollarFormatItemRenderer();
override public function set data(value:Object):void {
if( value != null ){
super.data = value;
if( !(value is DataGridColumn) && dataField != null
&& value[dataField] != null ){
dataString = value[dataField];
obj:Object;
]]>
</mx:Script>
<mx:CurrencyValidator id="pnV" source="{ti}"
property="text"
trigger="{ti}" triggerEvent="change" required="true" />
<mx:TextInput id="ti" text="{dataString}"
updateComplete="dataString=ti.text;"
change="dataString=ti.text;"/>
</mx:HBox>
I'm adding it to my DataGrid as follows:
[Bindable] private var cf1:ClassFactory = new ClassFactory(
GenericDollarFormatItemRenderer );
cf1.properties = { dataField: 'price' };
<mx:DataGridColumn headerText="price" textAlign="right"
editable="true" itemRenderer="{cf1}" />
The data source for the data grid is e4x XML drawn from an
HTTPService.
Any experts out there can elucidate this one? If I'm on the
completely wrong track, let me know! This is a needed to be done
yesterday type of thing :)
Thanks
AlexWorst forums ever! Nobody can help with the insertion of a
currencyvalidator in a datagrid itemeditor? -
LabelFunction for cell datagrid validation
private function price(item:Object, column:DataGridColumn):String {
if (item.col1.length !=9) { return item.col1 + "error" };
if (item.col2.length > 15){ return item.col2 + "error"};
if (item.col2.length > 10){ return item.col3 ,setStyle("color", 0xff0000) + "error" };
can someone please help me out with this function im trying to validate the items on a datagrid for lenght of theirs string but when i try to do it this way i get really bad errors.
<mx:DataGridColumn headerText="Vendor Number" dataField="col1" itemRenderer="PriceLabel" />
<mx:DataGridColumn headerText="Invoice Number" dataField="col2" itemRenderer="PriceLabel"/>
<mx:DataGridColumn headerText="Invoice Date" dataField="col3" />
i like to validate each column separetely but its seems to try to do it all at once.
Any help would be greatly appreciated.
Thanks
youTry using else if for the last two if statements.
But you should probably check the column first, then do the formatting, using the column parameter.
I'll show you how if you don't know. -
When clicking on datagrid row it throws me exception - WPF C#
Whenever I try to double click my datagrid row to edit it, I throws me a few exceptions which doesn't say anything to me. Hovever if
I set the whole datagrid to IsReadOnly to true, I want have the problem, but I need the second and third columns editable.
XAML
<DataGrid x:Name="clientList" HorizontalAlignment="Left" Height="225" Margin="11,126,0,0" VerticalAlignment="Top" Width="349" IsSynchronizedWithCurrentItem="False" AutoGenerateColumns="False" HorizontalGridLinesBrush="#FFB9B9B9" VerticalGridLinesBrush="#FF8B8B8B" GridLinesVisibility="Horizontal" CellStyle="{StaticResource Body_Content_DataGrid_Centering}">
<DataGrid.Resources>
<LinearGradientBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" StartPoint="0,0" EndPoint="0,1" >
<GradientStop Color="#66240000" Offset="0"/>
<GradientStop Color="#CC240000" Offset="0.65"/>
</LinearGradientBrush>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Width="30" Header="Id" IsReadOnly="True" Binding="{Binding Id}"/>
<DataGridTextColumn Width="100" Header="Company" IsReadOnly="False" Binding="{Binding Company}"/>
<DataGridTextColumn Width="130" Header="Name, Surname" IsReadOnly="False" Binding="{Binding Name}"/>
<DataGridTemplateColumn Header="Actions" CellTemplate="{StaticResource myTemplate}"/>
</DataGrid.Columns>
</DataGrid>
C#
clientList.Items.Add(new DataClients { Id = 1, Company = "My Company", Name = "Jane Roe"});
Exceptions
Exception:Thrown: "'EditItem' is not allowed for this view."(System.InvalidOperationException)
Exception:Thrown: "The string was not recognized as a valid DateTime. There is an unknown word starting at index 0." (System.FormatException)You need to set the ItemsSource property of the clientList DataGrid to a collection of DataClients objects that supports editing. HashSet<DataClients> does not for example but List<DataClients> and ObservableCollection<DataClients> does.
You could call the ToList() method on the collection that you set as the ItemsSource for the DataGrid to convert it to a List<DataClients>:
clientList.ItemsSource = yourCollection.ToList();
The "The string was not recognized as a valid DateTime" error message should be pretty self-explanatory. You are trying to convert a string which doesn't contain a valid date or time value to a DateTime value somewhere, perhaps in the 'myTemplate'.
There is nothing in the DataClients class that you have posted that will cause this exception to be thrown so it is impossible for anyone to tell.
But please only ask one question per thread and then start a new thread if you have a new question.
Please also remember to mark helpful posts as answer to close your threads. -
How to hide column of DataGrid
I am making a web part in which I am using System.Web.UI.WebControls.DataGrid control.
It's AutoGenerateColumns property is set to TRUE.
I am trying to hide a column at run time. I have written the following code on this controls ItemCreated event but it only works if I e.Item.Cells[0] and it doesn't work for any other value for e.g. e.Item.Cells[1] and e.Item.Cells[6].
There are 9 columns in my DataGrid control.
Code
protected void grd1_ItemCreated(object sender, DataGridItemEventArgs e)
{ e.Item.Cells[0].Visible = false; //works fine
e.Item.Cells[1].Visible = false; //gives error e.Item.Cells[2].Visible = false; //gives error
Error
Specified argument was out of the range of valid values.
Parameter name: index
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
How to hide a particular column?Hi Frank,
You can try something similar to the below in 'RowCreated' event Instead
protected void gridView_RowCreated(object sender, GridViewRowEventArgs e)
e.Row.Cells[1].visible =false;
OR I would say hiding column is not something that is to be done at row level, so you can hide columns outside any of the grid view event after binding.
e.g.
gridview1.columns[1].visible=false;
I am using DataGrid control in which there is no RowCreated event.
I have tried second approach but it also doesn't work. -
Can spark datagrid mouse click be disabled while in a custom item editor?
Hi,
Is it possible to prevent a user from clicking on another cell in a datagrid until the cell currently being edited has had its data saved?
I would like to validate the cell's text data as it is being entered by a user, character by character. If the validation fails, I would like to put up an error message and prevent the user from clicking outside of the cell. I am able to validate the data and put up an error message. But I have not found a way, if there is one, of disabling mouse clicks in other cells. I've tried setting the IE's parent.editable, .enabled and .mouseEnabled properties to false. But none of these are working for me.
Thanks,
-Adobegillisisle2The session does stay if I hit the TAB or RETURN keys. I return false from my overridden save() function and the session stays keeping the user in the edit cell, allowing fixing the invalid data. But I don't get the same behavior when I click the mouse on another cell. In these cases, my save function is still called, and I still return false ( in the case where the validation fails ), but the edit session goes away.
Maybe you are looking for
-
HI Gurus, You might help us,weI need your strategical inputs. We have our 2nd company code SAP Roll-out, however the project stop. Migration was done way back July 2011.. and now 2012 they wanted to continue. What would be the best strategy to do in
-
Cannot create AR Invoice negative amount with WithHolding Tax negative amount via DI API
Hi All, I tried to create AR Invoice Document via DI API, but with negative amount and negative withholding tax amount. Document added successfully, but when i open the document in SAP, and i open WTax Table information, withholding tax amount become
-
HT4993 My iphone 4s is rebooting its self over and over again.
I phone is stuck in a loop of rebooting and can not get to home screen
-
Import Fail crm 2011 to crm 2013 Legacy component issue
Hi All We are getting issues during organization import from crm 2011 to crm 2013 , the error is "We have detected the presence of legacy component(s) during upgrade, these components are not supported in Dynamics CRM 2013. Please refer to upgrade l
-
Missing Parts check one level....can you confirm
Simple scenario. I have a 3 level BOM. Top level Item Mat A (make to order 82) > Mat X (make to stock strategy 40) > Component 1 (purchased). Stock: There is only stock for the Component 1 When I create an order for Mat A I get a missing part for Ma