c# devexpress gridview row collect - c#

c# devexpress gridview selected row count error
i want to get row from anouther form(gridcontrol), i tryed form.gridview.selected.row.count but its not working. what can i write for the get this count? and from other forms of money, i want to print labels to collect this form.
""
gridView1.Columns["money"].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
gridView1.Columns["money"].SummaryItem.DisplayFormat = "Toplam:{0:n2}";
gridView1.OptionsView.ShowFooter = true;
""
i tryed this code its working but on the gridview but i want to write other form in the label.

form1 have gridView1.
form2 have label2. label2 display Sum from gridView1.
form1 must has form2 as its field or property.
form2 must has method public void SetSum(money sum) to set sum for label2.
Every count sum (e.g by click button) call form2.SetSum(sum)
MainForm.cs - Hosts form1 and form2
public partial class MainForm : Form
{
private Form1 _form1;
private Form2 _form2;
public MainForm()
{
InitializeComponent();
_form2 = new Form2();
_form1 = new Form1(_form2);
}
private void btnForm1_Click(object sender, EventArgs e)
{
_form1.Show(this);
}
private void btnForm2_Click(object sender, EventArgs e)
{
_form2.Show(this);
}
}
Form1.cs
public partial class Form1 : Form
{
private Form2 _receivedForm;
public Form1()
{
InitializeComponent();
}
public Form1(Form2 receivedForm) : this()
{
_receivedForm = receivedForm;
}
private void btnSend_Click(object sender, EventArgs e)
{
_receivedForm.SetSum(txtSum.Text);
}
}
Form2.cs:
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public void SetSum(string sum)
{
lblSum.Text = sum;
}
}
Hope this help. :D

ı did with this code now is working. thanks for all answer
DataBaseDataContext db = new DataBaseDataContext();
var sum = (from ord in db.safes select ord.money).Sum();
lbl_safein.Text = sum.ToString();

Related

C# : Modifying form1's listbox using form2's command button

I'm trying to make this simple program using Visual Studio C# 2013.
program screenshot: http://i.imgur.com/4QVbaa2.png
The listbox named receiptbox modifier was set to public using the properties panel.
Basically I am using 2 forms, what I want to happen is to show the quantity + the name of the food in the form 1's listbox.
This is the code when you click the food icon on form1:
private void pictureBox1_Click(object sender, EventArgs e)
{
FoodQty form2 = new FoodQty();
form2.Show();
}
It will show form2.
This is the source-code in the form2 and when you click its Ok button:
public partial class FoodQty : Form
{
Form1 mainfrm = new Form1();
Record recordInstance = new Record();
public FoodQty()
{
InitializeComponent();
}
private void btnOk_Click(object sender, EventArgs e)
{
mainfrm.receiptBox.Items.Add((int)numericUpDown1.Value + recordInstance.foodMenuArray[1]); // converts numupdown to int and appends the string array
}
}
Try this :
in form 1 :
private void pictureBox1_Click(object sender, EventArgs e)
{
FoodQty form2 = new FoodQty(this);
form2.Show();
}
in fom2 :
public partial class FoodQty : Form
{
Form1 mainfrm = new Form1();
Record recordInstance = new Record();
public FoodQty( Form1 fr)
{
InitializeComponent();
mainfrm =fr;
}
private void btnOk_Click(object sender, EventArgs e)
{
mainfrm.receiptBox.Items.Add((int)numericUpDown1.Value + recordInstance.foodMenuArray[1]); // converts numupdown to int and appends the string array
}
}

C# - Fill Listview in a different form - VS2015

I have 2 forms. Form 1 which shows a ListView and Form 2 a button called button1.
What I'm trying to do is when the button on form 2 is clicked. I want it to fill the Listview on form1.
The listview has 3 columns;
Flavour
Quantity
Sub-Total
When the button1 is pressed, it should show Vanilla, 1, £1.00 in the listview on form1.
I'm able to do this if the listview is on the same form as the button, but not if it's on different forms.
Form1
public partial class form1: Form
{
public form1()
{
InitializeComponent();
}
Form2
public partial class form2: Form
{
public form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ListViewItem lvi = new ListViewItem("Vanilla");
lvi.SubItems.Add("1");
lvi.SubItems.Add("£1.00");
listView1.Items.Add(lvi);
}
Create a reference of form1 in form2 like this:
class Program {
static void Main() {
var form1 = new Form1();
var form2 = new Form2(form1);
}
}
public partial class Form1: Form
{
public Form1()
{
InitializeComponent();
}
public void DoStuff(ListViewItem lvi) {
// TODO: Stuff
}
}
public partial class Form2: Form
{
private Form1 _form1;
public form2(Form1 form1)
{
InitializeComponent();
_form1 = form1;
}
private void button1_Click(object sender, EventArgs e)
{
ListViewItem lvi = new ListViewItem("Vanilla");
lvi.SubItems.Add("1");
lvi.SubItems.Add("£1.00");
listView1.Items.Add(lvi);
_form1.DoStuff(lvi);
}
}

Application Windows Form C# use menu (User control)

I have an application with 2 Forms, for those forms I have create a Menu which I depose on the two forms.
There is only a menuStrip item on the menu, I just want when I click on "test1" to redirect to Form1 and when I click to "test2" I want to redirect to Form2.
But if test1 is already open/display I don't want to show him again and the same for test2.
My code in my Menu :
public partial class Menu : UserControl
{
public Menu()
{
InitializeComponent();
}
private void test1ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form1 f1 = new Form1();
Form2 f2 = new Form2();
f2.Hide();
f1.Hide();
f1.ShowDialog();
}
private void test2ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form1 f1 = new Form1();
Form2 f2 = new Form2();
f1.Hide();
f2.Hide();
f2.ShowDialog();
}
}
My Form1 :
My Form2 :
I just want the same result like my Buttons in Form1 and Form2 :
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
Form1 f1 = new Form1();
f1.ShowDialog();
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
Form2 f2 = new Form2();
f2.ShowDialog();
}
}
I thought that the property Visible for forms could help me but not...
The problem is when I click on my buttons it's open a new window but when my form is already open I don't want to open it again.
Thanks for your reply, I hope that I am clear sorry for my english in advance.
You are currently creating a new form each time the click handler code is executed.
Here is one way, but its nasty and I wouldn't really recommend it. I've assumed that form1 is the entry to your application and that its also the exit of the application. This solution uses a singleton to hold the f1/f2 instances.
public static class Global
{
static Global()
{
f2 = new Form2();
}
public static Form f1;
public static Form f2;
}
Your menu altered:
public partial class Menu : UserControl
{
public Menu()
{
InitializeComponent();
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
Global.f2.Hide();
Global.f1.Hide();
Global.f1.Show();
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
Global.f1.Hide();
Global.f2.Hide();
Global.f2.Show();
}
public void SetForm1(Form form)
{
Global.f1 = form;
}
public void SetForm2(Form form)
{
Global.f2 = form;
}
}
And the forms:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Global.f1 = this;
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
Global.f2.ShowDialog();
}
}
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
Global.f1.Show();
}
}
Hope this helps.
Your logic is wrong.
It seems to me that you want to display different content depending on the user selection on that 'menuStrip'. You need to look at dynamic controls loading not different forms loading.
You can have just a MainForm with that 'menuStrip' and a Panel. Define some User Controls and dynamically add them to that panel based on the user selection.
Snippet
public MainForm : Form
{
public MainForm()
{
// code
}
public void MenuStrip_OptionSelected(object sender, EventArgs e)
{
Panel1.Controls.Clear();
switch(MenuStrip.SelectedValue)
{
case "UserControl1" : Panel1.Controls.Add(new UserControl1()); break;
...
}
}
}
public UserControl1 : UserControl
{
// code
}

display comboBox value of fom1 to another form in Textbox

I have three forms Form1, Form2 and Form3. I have a comboBox in form1 which I want it to be displayed in Form 3.
Question: So what I want is that when I select the value of comboBox in form1 and click the button, it should open form2 and in form2 when I click the button again, It should show the comboBox selected value in a textbox in Form3.
private void button1_Click(object sender, EventArgs e) //form1
{
Form2 f2 = new Form2(); // don't know what to put in this parameter
f2.ShowDialog();
}
ComboBox CB1;
public Form2(ComboBox cb1)
{
InitializeComponent();
CB1= cb1;
cb1.Text.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
Form3 f3 = new Form3(CB1);
f3.ShowDialog();
}
public partial class Form3 : Form
{
ComboBox Combo;
public Form3(ComboBox combo)
{
InitializeComponent();
Combo = combo;
Combo.Text = combo.ToString();
}
SOLUTION1:
One simple solution is defining a static property in your first window for the selected item,
public static string SelectedItem;
public MainWindow()
{
InitializeComponent();
}
And in Window3, you can assign the value like this,
public Window3()
{
InitializeComponent();
txtresult.Text = MainWindow.SelectedItem;
}
SOLUTION2:
If you have to pass the value through the constructor just pass the selectedItem as a String through each window, something like this,
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2(combobox.SelectedItem.ToString());
f2.ShowDialog();
}
string result = null;
public Form2(String selected)
{
InitializeComponent();
result = selected;
}
In form 3,
public Form3(string result)
{
InitializeComponent();
Combo.Text = result();
}
In the event from form1 to form2
Form2 obj = new Form2(ComboBox1.SelectedValue);
this.Hide();
Form2.Show();
In form2:
string someName="";
public form2(string name)
{
InitializeComponent();
someName=name;
}

C# Pass selection from listbox in form1 to textbox in form2

I've got two forms and a custom class. I have populated a listbox in form1 using my custom class which holds several data types. I want to pass each of those values in the class located in the listbox to individual text boxes in form2. I'm having trouble figuring out how to access the individual values in each listbox instance of my class and then split them among the text boxes in form2. I thought I was on the right track by creating a property on form2 for my first textbox. I only have the one property set up right now because I wasn't sure it would work and was only testing. In form1 I was trying to set it up so I could access my class values from the selected item.
Form 1
private void propertiesToolStripMenuItem_Click(object sender, EventArgs e)
{
frmProperties editProperties = new frmProperties();
DialogResult result = editProperties.ShowDialog();
object employeeSelect = lstBoxEmployees.SelectedValue;
editProperties.TextFirstName = Convert.ToString(employeeSelect);
}
form 2
public partial class frmProperties : Form
{
public string TextFirstName
{
get { return txtFirstName.Text; }
set { txtFirstName.Text = value; }
}
public frmProperties()
{
InitializeComponent();
}
}
Form 1:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnOpenForm2_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2(this);
f2.ShowDialog();
}
public string ListBoxValue
{
get { return listBox1.SelectedItem.ToString(); }
}
}
Form 2:
public partial class Form2 : Form
{
Form1 f1;
public Form2(Form1 f1)
{
this.f1 = f1;
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
textBox1.Text = this.f1.ListBoxValue;
}
}

Categories

Resources