Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
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
C#
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
C#
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

C#
if (getset.big != null)
                {
                    // trying to displaying here
                    MessageBox.Show(getset.big);
                }
                else
                {
                    MessageBox.Show("Problem is in Image");
                }

other button code

C#
private void button6_Click(object sender, EventArgs e)
        {
// here it has been set
            getset.big = "fddfdf";
        }
Posted
Updated 8-Aug-12 8:46am
v2
Comments
[no name] 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 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
[no name] 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 8-Aug-12 14:40pm    
I have set the value first and try to read
[no name] 8-Aug-12 15:13pm    
Check to see if fileName = OpenFD.FileName; is actually returning a value.

sorry all it was a mistake that I am using twice button and setting on other and trying to get from other
 
Share this answer
 
Ok, the helper class (getset.cs) is:
C#
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):
C#
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.
 
Share this answer
 
v4
Comments
Kislay Raj 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 8-Aug-12 14:36pm    
I don't see any error. Add public in front of your class declaration.
Kislay Raj 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 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 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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900