Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help with DataGridView Validation

jbassmanpjbassmanp Posts: 160Member
I am new to this type of programming (working directly with the datagrid)
and I'm hoping someone has the answer. I have and application the data is
entered by way of Textboxes where all the text formatting is done and
validated. The saved entries a sent to the datagrid table to view. If a
mistake is not caught before this move. Some editing directly to the
datagrid is needed. I would like to force some text formatting such as
uppercase to one table. I am using the following coding. The only problem
is it works sometime on the first enter key press but not allways. If I
re-enter on that cell it will convert to upper case can someone show me
where I'm going wrong.... Code is as follows:


[code]
Private Sub DataGridView1_CellValidating(ByVal sender As Object, ByVal
e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles DataGridView1.CellValidating

StrNew = e.FormattedValue.ToString
DataGridView1.Item(e.ColumnIndex, e.RowIndex).Value = UCase(StrNew)

end sub
[/code]


Comments

  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    Sounds like the CellValidating event isn't always triggered. Try other events; perhaps something like CellChange?

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • jbassmanpjbassmanp Posts: 160Member
    : Sounds like the CellValidating event isn't always triggered. Try
    : other events; perhaps something like CellChange?
    :
    : Best Regards,
    : Richard
    :
    : The way I see it... Well, it's all pretty blurry

    Tried CellValueChange and CellEnter, as CellChange was not a valid option. It still didn't work. Any other ideas. All I want to do is force the entries to Uppercase without makeing the users cap lock or worry about that. I'm doing that work for them (user friendly).
  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member

    : Tried CellValueChange and CellEnter, as CellChange was not a valid
    : option. It still didn't work. Any other ideas. All I want to do is
    : force the entries to Uppercase without makeing the users cap lock or
    : worry about that. I'm doing that work for them (user friendly).
    :

    I think the best way is to validate the items before they are sent to the datagrid. You said the user uses textboxes to fill in information. If you add the text to the grid, just cast it to upper case.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • jbassmanpjbassmanp Posts: 160Member
    :
    : : Tried CellValueChange and CellEnter, as CellChange was not a valid
    : : option. It still didn't work. Any other ideas. All I want to do is
    : : force the entries to Uppercase without makeing the users cap lock or
    : : worry about that. I'm doing that work for them (user friendly).
    : :
    :
    : I think the best way is to validate the items before they are sent
    : to the datagrid. You said the user uses textboxes to fill in
    : information. If you add the text to the grid, just cast it to upper
    : case.
    :
    : Best Regards,
    : Richard
    :
    : The way I see it... Well, it's all pretty blurry
    I force uppercase in the textbox entries before as stated in earlier post. But sometimes (not often/ in fact very rare) the users need to edit the datagrid entries. This is where I want to make sure the text remain uppercase. There should be a way of forcing this. I don't want to leave it up to them, as programmers we should be able to do this. My application is already in deployment an every now and then the none uppercase edits slide into the picture (from end-users who forgot to change case). I want to stop it as it muddies the water.
  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    In such cases a xxxValidating event proceeds a xxxValidated event. Validating has a Cancel option (thus it is used for checking whether the user has entered valid data, and can stop the update if not), Validated is used to apply small edits to furtherly correct data (like casting to uppercase).

    Could you please test the validated event code, and then tell me in which exceptional situations it doesn't work?

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • jbassmanpjbassmanp Posts: 160Member
    : In such cases a xxxValidating event proceeds a xxxValidated event.
    : Validating has a Cancel option (thus it is used for checking whether
    : the user has entered valid data, and can stop the update if not),
    : Validated is used to apply small edits to furtherly correct data
    : (like casting to uppercase).
    :
    : Could you please test the validated event code, and then tell me in
    : which exceptional situations it doesn't work?
    :
    : Best Regards,
    : Richard
    :
    : The way I see it... Well, it's all pretty blurry
    You just might have answered the puzzle. If you need the valdating event to be followed by the validated event then I need to add a validating event to finish the process. Thus not needing to press enter on the cell twice. It has always worked but required pressing enter twice. Let me try this....
    PS: I'm back it worked first time great thank you. I'm New to this manipulation of datagrid cells.
    Thanks !!!!
Sign In or Register to comment.