Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 800779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:20:30+00:00 2026-05-14T23:20:30+00:00

Its better to accept my mistake with this question. I messed up things thats

  • 0

Its better to accept my mistake with this question. I messed up things thats why i had this problem. Sorry for bothering you people …

string name = ((DateTimePicker)sender).Name.ToString();
        name = name.Substring(0, name.Length - 1);
        name = name + "4";
        TimeSpan duration = new TimeSpan();
        duration = ((DateTimePicker)sender).Value - ((DateTimePicker)panel2.Controls[name]).Value;
        name = name.Substring(0, name.Length - 1);
        name = name + "6";
        ((MaskedTextBox)panel2.Controls[name]).Text = duration.ToString();

On execution it gives me Object reference not set to instance of an object
similar functionality is used on other places but I can’t find out what I have to reinitialize here :$

alt text http://www.freeimagehosting.net/uploads/735eefb5db.jpg

The casting for datetimepicker is fine
I have to get a name for the datetiempicker to identify the row it’s on in my form
and the picker before that to calculate their differences and then print that difference in a maskedtext box from the control whose name I make using names of two datetimepickers but when I access controls in the error line I get this message.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:20:30+00:00Added an answer on May 14, 2026 at 11:20 pm

    Lots…

    Use String.Format() to make this a little clearer. It’s OK to not use StringBuilder for this, but it’s real hard to understand what you are trying to do.

    Also, things like the

    (DateTimePicker)sender 
    

    Should not be repeated. Cast once, and reuse the cast object.

    DateTimePicker _castObject = (DateTimePicker)sender;
    

    The obj not ref error could be on any of these objects. Unless you step through, or add defensive statements (below), you are going to have a heck of a time figuring it out.

    if (sender == null)
    { throw new ArgumentNullException("sender", "sender is null");}
    

    If this is happening in a standard event handler on your form, it would look something like this (excuse the VB, I cant do c# from memory anymore).

    Protected Function btnOK_Click(sender as Object, e as EventArgs) Handles btnOK.Click
     'your code'
    End Function
    

    If you see something similar, then there is no reason to cast any object on the form. Just access it by its control name (btnOK, txtMaskedTextBox, etc).

    You seem to be going about something here in an entirely wrong way. Perhaps you should start by explaining the actual problem you are trying to solve instead of this specific exception. See “thin metal ruler“.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've looked around, but don't see this question - maybe its too easy, but
This is a follow up post to some problems I've had using Java built
EDIT NOTE I am rewording this question entirely now that I have a bit
I'm creating a function which can accept a string which is either retrieved through
The HTML5 <canvas> element does not accept relative sizes (percent) for its width and
This was a question about testing file upload functionality using a local java server
Recently I had a problem. How to disable scrolling in a particular area of
I have read an why it's better and how it's implemented . But what
The book, Producing Open Source Software , suggests that it's better to have lengthy
I recently upgraded to Oracle Sql Developer 2.1 It's far better, but the query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.