Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET WindowsForms
Hello all, I am getting error when I trying to set value using get set method it retun null here, and from other button it is working fine. am i missing some thing? please help
private void button7_Click(object sender, EventArgs e)
        {
             OpenFD.Title = "Select Files";
            OpenFD.Filter = "Jpg|*.jpg|Jpge|*.jpge|Gif|*.gif";
            OpenFD.FileName = null;
            string fileName;
            if (OpenFD.ShowDialog() != DialogResult.Cancel)
            {
                querybuilder qu = new querybuilder();
                fileName = OpenFD.FileName;
          // setting the value here for getset.big
                getset.big = fileName;
                Object refmissing = System.Reflection.Missing.Value;
                try
                {
                    pictureBox2.Load(fileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error" + ex.Message.ToString());
                }
            }
        }
class for setting big is
    class getset
    {
        public static string photo;
        public static string big
        {
            get { return photo; }
            set { photo = value; }
        }
    }
and when I am trying to give out put then it return null while from other button when i am trying to set the value it work fine can any one help me please
 
if (getset.big != null)
                {
                    // trying to displaying here
                    MessageBox.Show(getset.big);
                }
                else
                {
                    MessageBox.Show("Problem is in Image");
                }
other button code
 
private void button6_Click(object sender, EventArgs e)
        {
// here it has been set
            getset.big = "fddfdf";
        }
Posted 8-Aug-12 8:19am
Edited 8-Aug-12 8:46am
v2
Comments
Wes Aday at 8-Aug-12 14:23pm
   
After all of this you left out the most crucial bit of information.... what is the error message?
Kislay Raj at 8-Aug-12 14:28pm
   
no error message infact when I try to load photo and same function I want to set the value using get set method then result I am getting null while when I am trying to set from other button it will set and I can see the value
Wes Aday at 8-Aug-12 14:35pm
   
So when you try and get the value does it in fact have a value to get? Have you set photo to be some default value? Or are you trying to read the value before any value is set?
Kislay Raj at 8-Aug-12 14:40pm
   
I have set the value first and try to read
Wes Aday at 8-Aug-12 15:13pm
   
Check to see if fileName = OpenFD.FileName; is actually returning a value.
Kislay Raj at 8-Aug-12 23:56pm
   
ya it is returning value so that I can see/ load image sucessfully but problem in setting values
Sergey Alexandrovich Kryukov at 8-Aug-12 14:41pm
   
Tag the application type of UI library you use: WPF? Forms? Silverlight? ASP.NET? what?
--SA
Kislay Raj at 8-Aug-12 14:45pm
   
Windowform ok
Sergey Alexandrovich Kryukov at 8-Aug-12 15:13pm
   
Thank you.
--SA
Sergey Alexandrovich Kryukov at 8-Aug-12 15:18pm
   
This hardly can work: you don't show essential code. Why the class getset, purpose of it. You just show your check for null, don't show how you initialize the variable...
It needs some minimalistic but complete code sample, not your present code. By the way, chances are, you can find the problem yourself while preparing the sample; it often happens.
--SA
Kislay Raj at 8-Aug-12 15:22pm
   
the project is too big to post over internet. ya I am trying to find my self and will try to see other option to
Sergey Alexandrovich Kryukov at 8-Aug-12 15:26pm
   
Exactly. Pay attention: above, I suggested that you should develop a special code sample, specially for asking a question, focusing only on the isolated problem.
--SA
Kislay Raj at 8-Aug-12 15:32pm
   
ya thanks for suggestion my friend
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Ok, the helper class (getset.cs) is:
using System;
 
namespace WindowsFormsApplication2
{
    public class getset
    {
        public string photo;
        public string big
        {
            get { return photo; }
            set { photo = value; }
        }
    }
}
 
The Form1.cs c# code is (button1 reproduces your button7):
namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            getset setter = new getset();
 
            setter.big = "hi!";
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFD.Title = "Select Files";
            OpenFD.Filter = "Jpg|*.jpg|Jpge|*.jpge|Gif|*.gif";
            OpenFD.FileName = null;
            string fileName;
            DialogResult result = OpenFD.ShowDialog();
            if (result == DialogResult.Yes || result== System.Windows.Forms.DialogResult.OK)
            {
                //querybuilder qu = new querybuilder();
                fileName = OpenFD.FileName;
                // setting the value here for getset.big
                getset setter = new getset();
                setter.big = fileName;
 
                try
                {
                    pictureBox2.Load(setter.big);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error" + ex.Message.ToString());
                }
            }
        }
    }
}
 
Hope it helps.
  Permalink  
v4
Comments
Kislay Raj at 8-Aug-12 14:34pm
   
No I have tried it, it's not working... look my question It is set from other button successfully but it is problem in setting it in button7 where I want to load picture to. I think I am missing something and I know one thing is that error is in Button7 in above code
Christian Amado at 8-Aug-12 14:36pm
   
I don't see any error. Add public in front of your class declaration.
Kislay Raj at 8-Aug-12 14:43pm
   
All classes and function I have to work with get and set I have publish and you can see above that no other function I have used which is not publish
Christian Amado at 8-Aug-12 14:46pm
   
You wrote: class getset. Must be: public class getset. And remove static key word. You need objects (instance of a class not a static class for this).
Kislay Raj at 8-Aug-12 14:48pm
   
I have tried both and it is in same file so I think it is not matter. one thing I would like to tell you that error is not in class getset it is in button7 which I couldn't find my friend
Christian Amado at 8-Aug-12 14:50pm
   
Let me reproduce it. I'll answer you in a moment.
Kislay Raj at 8-Aug-12 14:52pm
   
thank you very much I am waiting for answer
Christian Amado at 8-Aug-12 15:12pm
   
It's working for me! The image is loaded =)
Kislay Raj at 8-Aug-12 15:38pm
   
images has been loaded but can't set the value
Kislay Raj at 8-Aug-12 15:28pm
   
thanks but it's also not working both same thing. I had tried it before, having seen your answer I have tried it once again but it's not working
Christian Amado at 8-Aug-12 15:34pm
   
May be you have another issues different.
Kislay Raj at 8-Aug-12 15:39pm
   
may be but my question is for setting value not for loading image. in my code it has loaded to but didn't set
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

sorry all it was a mistake that I am using twice button and setting on other and trying to get from other
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 210
1 Richard MacCutchan 100
2 kbrandwijk 100
3 ProgramFOX 80
4 Mukesh Bhagat 65
0 Sergey Alexandrovich Kryukov 9,050
1 OriginalGriff 8,151
2 CPallini 2,613
3 Richard MacCutchan 2,221
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 9 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100