2
Answers

Urgent Help!!Crystal Report,RadioBtnList problem and Print Function using C#

fantasy_by

fantasy_by

20y
2.3k
1
hi all, i had encounter 2 problems while doing my project: (1) i'm using Crystal report to create an invoice. I need to get details for a particular invoiceID for instance: i want all details of invoiceID1 only, however, the crystal report give me the entire Invoice table's data! I heard that there's a way to solve this problem which is by passing parameter to the report...anyone here knows how to do it?i'll appreciate if there are detailed step by step procedure explained with C# code. By the way, i'm using a webform to generate the crystal report. (2) i'm using radiobtnlist and dropdownlist control in my webform. What code should i type inorder for the application to determine which option the user had selected and immdiately after the user selection, it will be updated to the database... For instance: Option A Option B The user had selected option A, immediately the selected option will be recorded into the database...what is the C# code to do so? (3) Anyone knows the C# code for prinnt function in webform? Let's say i want to print a form, there are 2 button: Print Preview and Print. What is the C# code for this 2 button in webform? Hope there's someone help me with this!thks alot!i really needs to know the codes,urgent!
Answers (2)
0
Zoran Horvat
NA 5.7k 516.3k 13y
You must check return value of FindForm:

string windowHandle = "Save As";
IntPtr hwnd = (IntPtr)FindWindow(null, windowHandle);

if (hwnd != IntPtr.Zero)
{
        SetForegroundWindow(hwnd);
        SendKeys.Send("{ENTER}");

}

Without this check you're sending ENTER key to currently active window, which is wrong.

Zoran
Accepted
0
Sam Hobbs
NA 28.7k 1.3m 13y
I would not do it that way. Experienced Windows programmers would know how to send a message to the dialog that notifies it that the okay button was clicked.

It is not clear to me if this is for the same process or a different process. If it is the same process and you have the code for program, then I don't understand why you are showing a save file dialog when you don't need it.
0
Bahar Jalali
NA 153 259.8k 13y
yes that's right!

i found that myself and wort like this:
///////////
private void timer1_Tick(object sender, EventArgs e)
        {
            string windowHandle = "Save As";

          //  Process[] word = Process.GetProcessesByName(programname);
            IntPtr hwnd = (IntPtr)FindWindow("#32770", windowHandle);
            IntPtr val = IntPtr.Zero;

            if (hwnd != val)
            {
                SetForegroundWindow(hwnd);
                SendKeys.Send("{ENTER}");
                timer1.Stop();
                timer1.Start();
            }
        }
///////////////////////////////////////

ant it's like your code
0
Bahar Jalali
NA 153 259.8k 13y
i use timer but it enters every program on windows that mouse go move on!

because the command <sendkey.send("{ENTER}")> is in the timer tick event!

and it execute this command on all programs.

i thinks when i put the code in a timer thick event, it can't detect "Save Az" window ! but i want when it detect a save as window then enters it.


///////////////////////////////////////

private void timer1_Tick(object sender, EventArgs e)
        {
            string windowHandle = "Save As";
            IntPtr hwnd = (IntPtr)FindWindow(null, windowHandle);
            label1.Text = hwnd.ToString();
            SetForegroundWindow(hwnd);
            SendKeys.Send("{ENTER}");
        }
//////////////////////////////////////


and it seems i need to a if command for check it
but i don't know how can i check it?!

and what about "static" in DLLs on the top of my code? is it possible my problem is maked for it?

any idea?!
0
Zoran Horvat
NA 5.7k 516.3k 13y
I've written you the code with timer in another thread you posted. Try with that, it should be sufficient for your needs.

Zoran
0
Bahar Jalali
NA 153 259.8k 13y
thanks
i put the code in form1_shown and form1_changevisible but dosn't work again

i put a timer and it fall in a EXTREME loop


could you test it ?

thanks
0
Zoran Horvat
NA 5.7k 516.3k 13y
You are executing this code from Form_Load method, i.e. from form's Load event handler. It means that code will be executed only once, and when form is shown for the first time. So you need to restart the application in order to execute this code again.

If you want the code to be executed every time the form is shown, then implement it in the Shown event handler.

Zoran
0
Bahar Jalali
NA 153 259.8k 13y
every body!
i find it and it works

it's the code

string windowHandle = "Save As";
IntPtr hwnd = (IntPtr)FindWindow(null, windowHandle);
SetForegroundWindow(hwnd);
SendKeys.Send("{ENTER}");

i put this code in form_load()

like this:
///////////////////////////////////////////////////////////

// Get a handle to an application window.
        [DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        // Activate an application window.
        [DllImport("USER32.DLL")]
        public static extern bool SetForegroundWindow(IntPtr hWnd);


        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
                string windowHandle = "Save As";
                IntPtr hwnd = (IntPtr)FindWindow(null, windowHandle);
                SetForegroundWindow(hwnd);
                SendKeys.Send("{ENTER}");             
        }
              
    }
}

//////////////////////////////////////////////////////////

now it work but it enter the first save dialog box on windows
and when i open a savedialog box again, it dosn't work

i try use if the form is already open but it dosn't work again.

please help me .
i want while my program is running , it enters all save dialog boxes.

thanks