I'm trying to populate a label on from. The value for this label is coming from another form which opens up the active current form where the label resides, is this even possible and if so can someone explain how to do it using the C# express designer.

how to populate label on different form.
redshock
use the listview click/item click event so when the user clicks, it will open the form which will eventually show the information.
So now you want to pass locID - well, where is this value on the form Is it bound to the listview as a value member
if so, just pass the SelectedValue property of the listview to the other form, which will then perform the query for you then do whatever you want with it.
As for the @locID - this is a parameter, so you need to add to the Sql/OleDbCommand parameter collection, this Sql/OleDbParameter and name the parameter as "@locID", giving the locID value, which will be passed in from the parent form
Vaassu
you need to have a reference/instance of that form in question, and then access the label property either by making the label control public (so its viewable/accessible by the caller class(es)) or create a public property which can get/set the label property.
Example of accessing other forms/controls:
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=765625&SiteID=1
same thing would apply for a label, except you just change the properties appropriately.
so, you want to change the value of a label from another form - you need a reference to the form with the label on the other form so you can access it.
so you could do something like this also:
//label form:
public string TheLabelText
{
get { return this.theLabel.Text; }
set { this.theLabel.Text = value; }
}
//other form:
Form2 theLabelForm = new Form2();
theLabelForm.TheLabelText = "set from the other form, the parent form";
As you can see, you have a public property in the label form, which allows the callers to access it, which then gets or sets the text property of the label, from the caller.
So, the caller (parent form) makes an instance of this label form, then sets the property in question, which then the label form does - sets the incoming value to the label on the form.
does this help
Takato
ok I tried doing the following:
on the locForm where the listbox resides:
private
void loclist1_Click(object sender, EventArgs e){
locationDetails locDetails = new locationDetails(this.loclist1.SelectedValue);locDetails.ShowDialog();
}
then I got this error:
Error 1 No overload for method 'locationDetails' takes '1' arguments C:\Documents and Settings\Reya276\My Documents\Visual Studio 2005\Projects\CaterManager\CaterManager\locForm.cs 82 42 CaterManager
Jacco Mintjes
most likely you didnt add a parameter to the form constructor as shown in the example ;-)
//Form2 (the one that has this label/execute query)
//global:
private object theItemValueChosen = null;
public Form2(object itemValueChosen)
{
if (itemValueChosen != null)
{
this.theItemValueChosen = itemValueChosen;
..
..
...
Vinod_Saastha
ok this is the entire code for the locForm.
using
System;using
System.Collections.Generic;using
System.ComponentModel;using
System.Data;using
System.Drawing;using
System.Text;using
System.Windows.Forms;namespace
CaterManager{
public partial class locForm : Form{
public locForm(){
InitializeComponent();
}
private void locationsDataGrid_Navigate(object sender, NavigateEventArgs ne){
}
private void locForm_Load(object sender, EventArgs e){
// TODO: This line of code loads data into the 'caterManager_DataDataSet.locations' table. You can move, or remove it, as needed. this.locationsTableAdapter.Fill(this.caterManager_DataDataSet.locations); // TODO: This line of code loads data into the 'caterManager_DataDataSet.locations' table. You can move, or remove it, as needed. this.locationsTableAdapter.Fill(this.caterManager_DataDataSet.locations);}
private void closeLoclink1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e){
locForm.ActiveForm.Close();}
private void listLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e){
locListPanel.Show();
listLabel1.Hide();
listLabel2.Show();
loclist1.Show();
}
private void listLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e){
locListPanel.Hide();
listLabel2.Hide();
loclist1.Hide();
listLabel1.Show();
}
private void fillToolStripButton_Click(object sender, EventArgs e){
try{
this.locationsTableAdapter.Fill(this.caterManager_DataDataSet.locations);}
catch (System.Exception ex){
System.Windows.Forms.
MessageBox.Show(ex.Message);}
}
private void fillByToolStripButton_Click(object sender, EventArgs e){
try{
this.locationsTableAdapter.FillBy(this.caterManager_DataDataSet.locations);}
catch (System.Exception ex){
System.Windows.Forms.
MessageBox.Show(ex.Message);}
}
private void loclist1_Click(object sender, EventArgs e){
locationDetails locDetails = new locationDetails();locDetails.Show();
}
private void locSaveBt_Click(object sender, EventArgs e){
}
}
}
redwood739
confused.
I don't know much about how you are doing this through the wizard/designer view. From what I understand, when the user clicks on an item in the listbox, which has been populated/bound from a datasource (dataset), you wish to open up another form, and execute a query correct if this is the case, simply create a listbox click/itemclicked event so this will fire when the user selects an item.
Next up, you need to obtain (I hope but working from limited info here) the ID record field of the item you clicked on. Now, when the ValueMember of the databound control has been set to the ID field of the datasource (dataset), this will give us the ID from the SelectedValue property of the listbox. This is what you may well be using as the @locID parameter in your SQL Statement on the next form.
So, IF this is all true then you may wish to try this, this code here is on the item clicked event of the listbox:
//
Form2 theOtherForm = new Form2(this.theListBox.SelectedValue);
theOtherForm.ShowDialog();
//Form2 (the one that has this label/execute query)
//global:
private object theItemValueChosen = null;
public Form2(object itemValueChosen)
{
if (itemValueChosen != null)
{
this.theItemValueChosen = itemValueChosen;
InitializeComponent(); //this is in here by default
}
else
{
throw new ArgumentException("parameter is null, cannot execute query without a valid value");
this.Close();
}
}
//some method which executes your SQL command in Form2:
SqlCommand theSqlCommand = new SqlCommand("SELECT STATEMENT HERE", "ConnectionStringHere");
SqlParameter locID = new SqlParameter("@locid", SqlDbType.DataTypeHere);
locID.Value = this.theItemValueChosen;
theSqlCommand.Parameters.Add(locID);
theSqlCommand.Connection.Open();
SqlDataReader theReader = theSqlCommand.ExecuteReader(CommandBehavior.CloseConnection);
while (theReader.Read())
{
//get your values returned by the command that has just been executed
}
theSqlCommand.Connection.Close();
I hope this helps in some way
dgibbons
reichard
ok this is what I want to do. I want to click a value on a listbox which resides on form1 then open form2 and pass the locid variable and perform this query:
SELECT locations.locid, locations.loc_name, locations.loc_manager, SUM(payroll.pay_amount) AS proll_amt, SUM(expensepro.expro_amount)
AS exp_amt, SUM(caterings.cater_amount) AS cater_amt, caterings.cater_paid, SUM(vendorpro.venpro_amount) AS ven_amt
FROM locations INNER JOIN
caterings ON locations.locid = caterings.locid INNER JOIN
vendorpro ON locations.locid = vendorpro.locid INNER JOIN
payroll ON locations.locid = payroll.locid INNER JOIN
expensepro ON locations.locid = expensepro.locid
GROUP BY locations.locid, locations.loc_name, locations.loc_manager, caterings.cater_paid
HAVING (locations.locid = @locid)
then display the value of "loc_name" on a text lable, this should not be that complicated. Also how in the world can I call @locid
this is what I'm trying to load when form2 opens
private
void locationDetails_Load(object sender, EventArgs e){
this.locationsTableAdapter1.locDtlQuery(this.caterManager_DataDataSet1.locations);}
now when I try to run the application I get these errors.
1. Error 1 The best overloaded method match for 'CaterManager.caterManager_DataDataSetTableAdapters.locationsTableAdapter.locDtlQuery(int)' has some invalid arguments C:\Documents and Settings\rangeles\My Documents\Visual Studio 2005\Projects\CaterManager\CaterManager\locationDetails.cs 21 13 CaterManager
2.Error 2 Argument '1': cannot convert from 'CaterManager.caterManager_DataDataSet.locationsDataTable' to 'int' C:\Documents and Settings\rangeles\My Documents\Visual Studio 2005\Projects\CaterManager\CaterManager\locationDetails.cs 21 53 CaterManager
saleyoun
first thing is first. Where are you getting locID from Meaning, I know you are obtaining it from the database which is then being bound to a listbox Can you show us the code for this on how you are binding the data to the listbox
Once done, we will move on from there and hopefully get this up and running
mahima
you mean like this:
private
void locationDetails_Load(object sender, EventArgs e){
this.locationsTableAdapter1.locDtlQuery(this.locationsTableAdapter1.locDtlQuery(sqlCommand1));}
you got to hang with me here since I'm new to this C# stuff, heck the whole .Net thing period
jbattat
Fradam
KrazyMGA
ok this is what I have.
on locForm I have a listbox called "loclist1" which has a displayMember of "locations.loc_name" a ValueMember of "locations.locid" and a SelectedValue equal to "caterManager_DataDataSet - locations.locid"
Now when I added this code to the click event for "loclist1"
private
void loclist1_Click(object sender, EventArgs e){
locationDetails theOtherForm = new locationDetails(this.theListBox.SelectedValue);theOtherForm.ShowDialog();
}
I Get this error when I tried running the application:
Error 1 No overload for method 'locationDetails' takes '1' arguments C:\Documents and Settings\Reya276\My Documents\Visual Studio 2005\Projects\CaterManager\CaterManager\locForm.cs 82 44 CaterManager
now does this mean