Click here to Skip to main content
15,905,323 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to pass parameters from one function to another??both the methods are inside the same class...i'm using VS 2010 Ultimate..the code is as shown below...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;
using System.Data.SqlClient;
namespace WpfApplication7

/// Interaction logic for Window3.xaml

public partial class Window3 : Window

public Window3()

private void Window_Loaded(object sender, RoutedEventArgs e)
private void Window_Loaded_1(object sender, RoutedEventArgs e)
private void comboBox1_Loaded(object sender, RoutedEventArgs e)
List data = new List();
// ... Get the ComboBox reference.
var comboBox1 = sender as ComboBox;
// ... Assign the ItemsSource to the List.
comboBox1.ItemsSource = data;

public void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
var comboBox1 = sender as ComboBox;
string value = comboBox1.SelectedValue as string;

public void FillDataGrid()

SqlConnection con = new SqlConnection("Data Source=ANAIK-PC;Initial Catalog=wpfstocks;Integrated Security=True");
string command = "select * from applel2";
SqlCommand cmd = new SqlCommand(command, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable("applel2");
dataGrid1.ItemsSource = dt.DefaultView;

Any suggestions???
Updated 2-Oct-14 23:54pm
[no name] 3-Oct-14 5:42am    
"any suggestion".... for what? One suggestion is learn how to format your code so it's readable. Another suggestion is to read the FAQ for hints on how to ask a question. Just dumping a bunch of code here with any explanation is not a question or description of any kind of a problem.

You can simply call a method (with appropriate arguments needed) from other method of same class.
Other technique may be use class level variable which would be accessible in both methods.

If you are having more specific question, please let me know exactly which method you want to call form other one.
Share this answer
A function (well, a method in your case) can pass parameters to another function by invoking it.
If this is not your scenario (e.g. you are calling sequentially both methods) then you may:
  • Expicitly pass the same parameters to both methods

  • Wrap the parameters in a class, make the first method return a reference an instance of such class, eventually use such reference as second method parameter.

  • Make the parameters available as members of the class (the same class of both methods)

  • ...
Share this answer

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