This is a migrated thread and some comments may be shown as answers.

dont allow spaces

2 Answers 47 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jay
Top achievements
Rank 1
Jay asked on 21 Jul 2009, 05:17 PM
I hope this is simple, how can I edit a cell to not allow spaces.  The cell is required, and if I hit the spacebar and then enter it accepts it. This is what I have to edit it right now:

 

private void StateRadGridView1_CellValidating(object sender, CellValidatingEventArgs e)

 

{

 

GridViewDataColumn column = e.Column as GridViewDataColumn;

 

 

if (e.Row is GridViewDataRowInfo && column != null && column.FieldName == "MntStaName")

 

{

 

if (string.IsNullOrEmpty((string)e.Value))

 

{

 

MessageBox.Show("Description cannot be blank.", "JMS Error Message", MessageBoxButtons.OK, MessageBoxIcon.Stop);

 

}

}

2 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 22 Jul 2009, 03:22 PM
Hi,

Saw your post.
I'm doing something similar on a RadTextBox like this....
    Private Sub TextBoxMyText_KeyPress(ByVal sender As System.Object, _  
        ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBoxMyText.KeyPress  
 
        Select Case Char.GetUnicodeCategory(e.KeyChar)  
            Case UnicodeCategory.SpaceSeparator  
                e.Handled = True 
            Case Else 
                e.Handled = False 
        End Select 
    End Sub 

Perhaps you can use something similar in the key press events?
Hope it helps
Rich
0
Victor
Telerik team
answered on 24 Jul 2009, 04:41 PM
Hello Jay,

Here is a sample ValueChanging event with minimal sanity checks which demonstrates how to prevent spaces:
 
void radGridView1_ValueChanging(object sender, ValueChangingEventArgs e)  
{  
    if (e.NewValue is string)  
    {  
        string newVal = e.NewValue as string;  
        if (newVal.Contains(" "))  
        {  
            e.Cancel = true;  
        }  
    }  
 
I hope this is what you were looking for.

All the best,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Jay
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Victor
Telerik team
Share this question
or