1. Create a select statement to get all the Menus to 1st dgv.
2. Create a select statement with a where clause depending of the dgv1 selection.
In both use DataTables, which can be bound to the dgv controls. As simple as that.
1. Create a select statement to get all the Menus to 1st dgv.
2. Create a select statement with a where clause depending of the dgv1 selection.
In both use DataTables, which can be bound to the dgv controls. As simple as that.
My part:
string value ="some value";
if (char.IsDigit(value[0]) && char.IsLetter(value[value.Length - 1]))
value = "00" + value;
Hi, to add to ddanbe`s post.
You can do it this way too:
foreach (DataGridViewRow row in dataGridView1.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
//CELL here does not have a property of HeaderText.
//so you can do it like ddanbe showed or:
string header = dataGridView1.Columns[cell.ColumnIndex].HeaderText;
}
}
Great example showed pritesh. I would only like to show you one more simplier, but the methods are less proptective, because they are marked ass public, so you can access to them from every class, but anyway:
//form1:
private void buttonAdd_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.AddMethod2();
f2.Show();
}
private void buttonDel_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.DeleteMethod2();
f2.Show();
}
//form2:
public void AddMethod2()
{
}
public void DeleteMethod2()
{
}
I did your homework, and you owe me a beer:
public partial class Form1 : Form
{
int[] scores;
public Form1()
{
InitializeComponent();
TextBox[] tbs = new TextBox[] { textBox2, textBox3, textBox4 };
foreach (TextBox tb in tbs)
tb.Enabled = false;
textBox1.KeyPress += new KeyPressEventHandler(textBox1_KeyPress);
textBox1.Focus();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != (Char)Keys.Back && !Char.IsNumber(e.KeyChar))
e.Handled = true;
if (e.KeyChar == (Char)Keys.Enter)
AddingNumbers();
}
private void buttonAdd_Click(object sender, EventArgs e)
{
AddingNumbers();
}
private void AddingNumbers()
{
if (textBox1.Text != "")
{
Array.Resize(ref scores, ((scores == null ? 1 : scores.Length + 1)));
scores[scores.Length - 1] = int.Parse(textBox1.Text);
//math operations for other textBoxes:
int _total = 0;
int _count = 0;
float _avg = 0;
for (int i = 0; i < scores.Length; i++)
{
_total += scores[i];
_count++;
}
_avg = _total / scores.Length;
//show all the results:
textBox2.Text = _total.ToString();
textBox3.Text = _count.ToString();
textBox4.Text = _avg.ToString();
}
}
private void buttonDiusplay_Click(object sender, EventArgs e)
{
Array.Sort(scores);
StringBuilder sb = new StringBuilder();
foreach (int score in scores)
sb.AppendLine(score.ToString());
MessageBox.Show(sb.ToString(), "Sorted scores");
}
private void buttonClear_Click(object sender, EventArgs e)
{
scores = null;
TextBox[] tbs = new TextBox[] { textBox1, textBox2, textBox3, textBox4 };
foreach (TextBox tb in tbs)
tb.Text = String.Empty;
textBox1.Focus();
}
private void buttonExit_Click(object sender, EventArgs e)
{
this.Dispose();
}
}
NO.
You cannot subtract or sum dateValues. You have to use TimeSpan`s method called Subtract.
like:
DateTime dt = (dateTimePicker1.Value);
TimeSpan ts = DateTime.Now.Subtract(dt);
textBox1.Text = (ts.Days * 30).ToString(); //or 20, or 10
I would stronglly reccomend, what has abelLazm proposed you, to change the event. Do not use SelectedIndexChaged, becuase you will have only problems. Use Click event.
What is the problem with SelectedIndexChnaged event is that it wires twice for the row selection. When you clik the listView for the 1st time it fires ones - thats ok, but as soon as you click it for the 2nd time, it will fire for the 1st clicked row, and for the 2nd time for the newly clicked row. So it can make your life very miserable, if oyur dont know how to handle it.
As said, use Click event and all will be fine - its the same thing.
I did an example code how to get items and subitems from lisrView:
public Form1()
{
InitializeComponent();
listView1.Columns.Add("Column1", 100, HorizontalAlignment.Left);
listView1.Columns.Add("Column2", -2, HorizontalAlignment.Center);
listView1.View = View.Details;
listView1.FullRowSelect = true;
//add some example rows:
for (int i = 1; i < 5; i++)
{
ListViewItem lvi = new ListViewItem(i.ToString() +".");
lvi.SubItems.Add("Column 2 - " + i);
listView1.Items.Add(lvi);
}
listView1.Click += new EventHandler(listView1_Click);
}
private void listView1_Click(object sender, EventArgs e)
{
string col1 = listView1.SelectedItems[0].Text;
string col2 = listView1.SelectedItems[0].SubItems[1].Text;
MessageBox.Show("1st column: " + col1 + "\n2nd column: " + col2);
}
If I understand you, you have 2+ columns in listView. And you would like to get the values from column1, column2, ... (if they are).
Am I right?
What???????
if (listView1.SelectedItems[0].SubItems[0].Text.ToString()) //...
Items or SelectedItems means 1st column, SubItems are 2nd and more columns, depends which index do you specify in the brackets.
SubItems[0] is 1st column, same as Items[0], so you have 2 options:
1. for choosing 1st column value : .SelecteItems[0].Text;
2. or choosing 2nd (or more) column value: .SelectedItems[0].SubItems[1].Text;
2.1 for choosing a value from the 3rd column: .SelectedItems[0].SubItems[2].Text;
I hope we clerified about Items and SubItems properties of the listView.
DateTime Staff_Total_Hours = (Convert.ToDateTime(textBox1.Text)).ToTimeSpan().Add( (Convert.ToDateTime(txtTime.Text)).ToTimeSpan());
does not solve the problem
Dont you see my post on this 2nd page on the top? This is your solution.
Yep, this will not do, it the comboBox is bound to a dataSet.
Try this one:
private void comboBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
int newID = Convert.ToInt32(table.Rows[table.Rows.Count - 1]["Id"]);
newID++;//add new id - add 1 to last id
//insert a new row to dataTable:
DataRow dr;
dr = table.NewRow();
dr["Id"] = newID++;
dr["Name"] = comboBox1.Text;
table.Rows.Add(dr);
}
else if (e.KeyCode == Keys.Escape)
this.Focus();
}
Consider that dataTable is done this way:
table = new DataTable("MyTable");
DataColumn[] columns = new DataColumn[] {
new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)) };
table.Columns.AddRange(columns);
List<string> list1 = new List<string>();
List<string> list2 = new List<string>();
string a = "100000";
string b = "011111";
string[] array = new string[]{a,b};
for (int i = 0; i < array.Length; i++)
{
if (array[i][0].ToString() == "1")
list1.Add(array[i]);
else
list2.Add(array[i]);
}
I have read your 1st post, and this is the colution for your troubles: :)
DateTime hour1 = Convert.ToDateTime(textBox1.Text);
DateTime hour2 = Convert.ToDateTime(textBox2.Text);
hour1 = hour1.AddHours(hour2.Hour).AddMinutes(hour2.Minute).AddSeconds(hour2.Second);
MessageBox.Show("Total date with hours is: " + hour1);
AS you can see, you have to convert both values to dateDate format. Then you have to add every sinlge date and/or time value to the date you want to "sum up". On this way you can add even years, months, miliseconds,..
bye, bye
Would you like to sum hours? I what format do you have hours?
In one textBox1 you have "10:00:00", that means "hour is 10am". What is in the 2nd textBox2?
YOu cannot use + operator on DateTime. What exactly would you like to do?
Heres an example how you have to use comboBox`s selectedValue method to get the actual Value (this is the ValueMember of the dataSurce, and the DisplayMember):
public Form1()
{
InitializeComponent();
DataTable table = new DataTable("MyTable");
DataColumn[] columns = new DataColumn[] {
new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)) };
table.Columns.AddRange(columns);
table.Rows.Add(1, "Mitja");
table.Rows.Add(2, "Nataška");
table.Rows.Add(3, "Karmen");
comboBox1.DataSource = table;
comboBox1.DisplayMember = "Name";
comboBox1.ValueMember = "Id";
//if you will add the event in a form designer, this event will fire while data binding, and you will get an error.
//so you do as I do here - code order, and adding the event here bellow!
this.comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
int intID = (int)comboBox1.SelectedValue;
//string strId = comboBox1.SelectedValue.ToString();
string strName = comboBox1.Text;
MessageBox.Show("User`s ID is: " + intID + "\nHis name is: " + strName);
}
Why do you use
comboBox1.SelectedValue;
?
Is there any particular reason? YOu would like to get thw ValueMember out of it, am I right?
Momerath is da Man, so there will surely wont be any exceptions, if only your other ocde runs fine :)
Yes, sorry, I wrote the code by heart, so errors can happen.
Repair the code to:
List<string> list;
private void button1_Click(object sender, EventArgs e)
{
list = new List<string>();
//code
}
You can use String.Format method, but it will return a string value of the time (not an actual time).
DateTime date = DateTime.Now;
string strTime = String.Format("{dd.MM.yyyy hh:mm}", date);
Do you explicitly wanna have a DateTime, and now a string?
If you only wanna add time (hours) you can simply use Add method in the time:
DateTime newTime = date.AddHours(2);
It this case it would be better to create some collection of the items. Lets say we use a generic list<T>, which will hold all the checked items, and those will be shown in listView2. So all you havw to do, is to copy all checked item to this list, and populate listView2 with all these items.
List<string> list;
private void button1_Click(object sender, EventArgs e)
{
list = new List();
for (int i = 0; i < listView1.Items.Count; i++)
{
if (listView1.Items[i].Checked)
{
list.Add(listView1.Items[i].SubItems[1].Text);
}
}
//clearing listView2
listView2.Items.Clear();
//populating listView2 from the list:
foreach(string item in list)
listView2.Text = item;
}
This code is better, it checks if the item exists in listView2. If it does not exists, it adds the item to listView2, if it exists, it does NOT add (it skips that one):
//code in the button click event:
for (int i = 0; i < listView1.Items.Count; i++)
{
if (listView1.Items[i].Checked)
{
string _item = listView1.Items[i].SubItems[1].Text;
//checking if this item exists in listView2:
//if not, its added to listView2
bool bInsert = true;
for (int j = 0; j < listView2.Items.Count; j++)
{
if (listView2.Items[j].Text == _item)
{
bInsert = false;
break;
}
}
if (bInsert)
listView2.Items.Add(_item);
}
}
public Form1()
{
InitializeComponent();
listView1.Columns.Add("Checking", 50, HorizontalAlignment.Center);
listView1.Columns.Add("Item name", -2, HorizontalAlignment.Center);
listView1.View = View.Details;
listView1.CheckBoxes = true;
listView2.Columns.Add("Item name", 100, HorizontalAlignment.Center);
listView2.View = View.Details;
//add some items to listView1:
for (int i = 0; i < 5; i++)
{
ListViewItem lvi = new ListViewItem();
lvi.SubItems.Add("Item " + i + 1);
listView1.Items.Add(lvi);
}
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < listView1.Items.Count; i++)
{
if (listView1.Items[i].Checked)
{
listView2.Items.Add(listView1.Items[i].SubItems[1].Text);
}
}
}
This code is not so good. You have already opened Form1, and its not a good practice to create a new instance of Form1.
Better would be as I showed you, to pass an instance of form1 as parameter to the class, where you would like to use it,
private void button1_Click(object sender, EventArgs e)
{
OtherClass otherclass = new OtherClass(this);//ADDED this- its a instance of Form1
NewThread = new Thread(new ThreadStart(otherclass.MyNewThread));
NewThread.Start();
}
////////////////////////
public class OtherClass
{
Form1 form1;
//constructor:
public OtherClass(Form1 _f1)
{
this.form1 = _f1;
}
public void MyNewThread()
{
Console.WriteLine("in OtherClass"); //my thread has started as this shows up in output
form1._UpdateLabel("New Text"); // This does not update the label text
}
}
If I understand you well, you would like to update a label on from1 from some other form, am I right?
For this you do not need delegates at all, and you do not need to start a new Thread either.
You can do it:
//form1:
public void UpdateLabel(string item)
{
this.label1.Text = item;
}
//form2:
Form1 f1;
public Form2(Form1 _f1)
{
//constructor of form2
Initializecomponent();
this.f1 = _f1;
}
private void button1_ClickUpdateLabelOnform1(objec sender, EventArgs e)
{
f1.UpdateLabel("New text to pass to form1 form form2");
}
Thats it.
Best would be to give us the code. Then we can point you into the righ direction...
You can mark the thread as answered, if you are satisfied with the asnwer, or add some at vote as helpful.
bye, bye
1st of all, you cannot have 2 select statements in the sqlDataApapter.
Next, you filled dataSet or 3 times with the same s(wrong) dataAdapter, without specifying which dataTable you want to fill.
See my code, and compare to yours.
Try this code:
SqlDataAdapter da1 = new SqlDataAdapter("select empid,citycode,name,salary from person", con);
SqlDataAdapter da2 = new SqlDataAdapter("select name,citycode from city", con);
DataSet ds = new DataSet("Person_City_Detaset");
DataTable dt1 = new DataTable("Person_Table");
DataTable dt2 = new DataTable("City_Table");
da1.Fill(dt1);
da2.Fill(dt2);
ds.Tables.AddRange(new DataTable[] { dt1, dt2 });
ds.Relations.Add("Person_City_Relation", dt2.Columns[1], dt1.Columns[1]); //use thisis needed!
Instead of using array, I would STRONGLY recommend you to use generic list instead. Its a WAY better "tool" to work with. Some exercise will sure be needed, but on the end you will be greatful to me, you will see :)
Ok, here`s the code I would like you to study:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter number of employees:");
Console.WriteLine("-------------------------");
int all = Convert.ToInt32(Console.ReadLine());
List<Employee> list = new List<Employee>();
string value;
for (int i = 0; i < all; i++)
{
Employee e = new Employee();
Console.WriteLine("Employee No.{0}:", i + 1);
Console.WriteLine("Enter user`s name:");
value = Console.ReadLine();
e.Name = value;
Console.WriteLine("Enter user`s age:");
value = Console.ReadLine();
e.Age = int.Parse(value);
list.Add(e);
}
Console.WriteLine("Thx for insertions...");
Console.WriteLine(".....................");
Console.WriteLine("Here are the results:");
foreach (Employee e in list)
Console.WriteLine("Employee {0} is {1} old", e.Name, e.Age);
Console.ReadLine();
}
}
class Employee
{
public string Name { get; set; }
public int Age { get; set; }
}
Dont forget to do the checking of the numbers. In case if the user enters a string while integer expected, there will be an error.
Did you think of something like this:
class Program
{
static void Main(string[] args)
{
List<Employee> list = new List<Employee>();
//lets add some data
list.AddRange(new Employee[]{
new Employee {ID = 1, Name = "John", Age= 28 },
new Employee {ID = 2, Name = "Ann", Age= 22 },
new Employee {ID = 3, Name = "George", Age= 30 }
});
Console.WriteLine("Please enter the id of the employee to get this data:");
int id = int.Parse(Console.ReadLine());
var userData = list.Where(w => w.ID == id).ToList();
foreach (var data in userData)
Console.WriteLine("Name is : {0}, Age is: {1}.", data.Name, data.Age);
Console.ReadLine();
}
}
class Employee
{
public int ID { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
...for the employee by Asking the user to enter the number of employees.
What does it mean to enter the number of employees?
What? Lol
Strange post of this CsharpChico guy. Code is even worse then of the thread`˙s creator.
This is something you would like to have I guess:
//creating a generci list for storing the wanted values
List<int> list = new List<int>();
using (StreamReader sr = new StreamReader(@"C:\1\test25.txt"))
{
string line;
int value;
int counter = 0;
while ((line = sr.ReadLine()) != null)
{
if (line.Contains(">"))
{
value = Convert.ToInt32(line.Remove(0, 1));
list.Add(value);
}
if (line != " ")
counter++;
if (counter == 4)
{
list.Add(Convert.ToInt32(line));
counter = 0;
}
}
}
What the code does, it to check if the line contains the ">" char. If it does, it addes the number beside the char to the array (in my case I used a generic list, whihc is way more appropriate to use then an array). Then if goes row by row forward.
Every this part consist of 4 NOT EMPTY rows. So there is a counter which counts all not empty rows (if row is empty there is no counting done). When counter reachers 4 (4th not empty row in the part) it add the number to the list again, and resets the couner. And story goes one form beginning.
I hope its understanadable enough.
Tell me, which values you want to get from this upper example? In each part are these 2 numbers:
1. the number on the right side of th ">" mark, and
2. the number which is just above the next ">" mark?
So in this example:
>25
233966
300156
89980
you would like to get 25 and 89980. Am I right?
I will show you how to do in both ways, becuase you didnt exactly specify in which direction you want to get a radio button check state.
So from from1 to check the radioButton on form2, and from form2 to check th radioButton on form1:
//FORM1
public partial class Form1 : Form
{
Form2 f2;
public Form1()
{
InitializeComponent();
}
public bool GetRadioButtonState_Form1()
{
return radioButton1.Checked ? true : false;
}
private void button1_Click(object sender, EventArgs e)
{
f2 = new Form2(this);
f2.Show();
}
private void button2_Click(object sender, EventArgs e)
{
//check for radio button on Form2:
if (f2 != null)
{
bool bChecking = f2.GetRadioButtonState_Form2();
MessageBox.Show("Radio button on Form1 is " + (bChecking ? "CHECKED!" : "NOT CHECKED!").ToString());
}
else
MessageBox.Show("First open form2...");
}
}
//FORM2:
public partial class Form2 : Form
{
Form1 f1;
public Form2(Form1 _f1)
{
InitializeComponent();
this.f1 = _f1;
}
public bool GetRadioButtonState_Form2()
{
return radioButton1.Checked ? true : false;
}
private void button1_Click(object sender, EventArgs e)
{
//Check for radio button on Form1:
bool bChecking = f1.GetRadioButtonState_Form1();
MessageBox.Show("Radio button on Form1 is " + (bChecking ? "CHECKED!" : "NOT CHECKED!").ToString());
}
}
Check here: http://www.codeproject.com/KB/cs/csharpmovewindow.aspx
Two ways. First:
//API functions to move the form
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HTCAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
//And in your mouse down event of the form:
public void Form1_MouseDown(object sender, MouseEventArgs e)
{
//If the left mouse is pressed, release form for movement
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
//Second:
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
int WM_NCHITTEST = 0x84;
if (m.Msg == WM_NCHITTEST)
{
int HTCLIENT = 1;
int HTCAPTION = 2;
if (m.Result.ToInt32() == HTCLIENT)
m.Result = (IntPtr)HTCAPTION;
}
}
I use the second. Its much simplier and doesn't use any API's. Though the first method is the one that I was using during my VB6 days...
You can use a Dictionary collection object:
public partial class Form1 : Form
{
Dictionary<string, string> connStrings;
public Form1()
{
InitializeComponent();
connStrings = new Dictionary<string, string>();
connStrings.Add("Connection string 1", "Your full connection string 1");
connStrings.Add("Connection string 2", "Your full connection string 2");
connStrings.Add("Connection string 3", "Your full connection string 3");
//the name in comboBox will be a value of dictionary
//the key of the dictionary will be the full connection string:
comboBox1.DataSource = new BindingSource(connStrings, null);
comboBox1.DisplayMember = "Value";
comboBox1.ValueMember = "Key";
comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string connString = ((KeyValuePair<string, string>)comboBox1.SelectedItem).Value;
MessageBox.Show("This is your connection string:\n" + connString);
}
}
If you still havent found the best way of showing specific data in the dgv, would you let me know? And if there is any code you have, would be more then welcome.
Instead of using that if statement:
if (Regex.IsMatch(allRead, regMatch))
I would suggest you, before doing a loop create an array of all characters (all the words in that string) :
string allRead = testTxt.ReadToEnd();
string allChars = allRead.Split(' ');
//create a new string wtih htmls:
string newString = null;
//your html string:
string htmlString = "Y:\\WorleyParsons\\Sasol Unit 17\\Submission Data\\Tru-View\\Unit17TruViewInterface\\TruView\\Unit17\\SiteMap.htm";
StringBuilder sb = new StringBuilder();
for(int i = 0; i < allChars.Lenght; i++)
{
//here do the Regex, or simple string Contains method checking
//if the char is your tag, add the html link:
//add the char:
sb.AppendText(allChars[i].ToString);
//and add the html link if "the e" is found:
if(allChars[i].Contains("e"))
sb.AppendText(htmlString);
}
//add newly created string from StringBuilde to a "newString" variable:
string newString = sb.Tostring();
This code i did heart, so there can be errors. I appologize for that.
But this is an example code how you can add your string into string.
On the 1st look, it looks ok to me. Even I cannot test the code atm.
Except the calculation of the triangle`s area. It has to be this way:
return _Area = this.Width * (this.Height / 2); }
Try it this way:
string path = @"C:myFolder\myFile.txt";
List<int> list = new List<int>();
using (StreamReader sr = new StreamReader(path))
{
string line;
while ((line = sr.ReadLine()) != null)
list.Add(Convert.ToInt32(line));
}
//generic list<T> now has all the numbers in the collection!
//generic list is better then a simple array (int[]).
You didnt start the correct way. Check out this code, I only did a half of the code, which calculates the square area:
namespace Apr11Test2
{
class Program
{
static void Main(string[] args)
{
Rectangle r = new Rectangle();
Square s = new Square(4, 5);
Console.WriteLine("Computed are is {0}.", s.ComputeArea(r.Area));
Console.ReadLine();
}
}
abstract class GeometricFigure
{
public double Width { get; set; }
public double Height { get; set; }
public readonly double Area;
public abstract double ComputeArea(double _Area);
}
class Rectangle : GeometricFigure
{
public override double ComputeArea(double _Area)
{
return _Area = this.Width * this.Height;
}
}
class Square : Rectangle
{
public Square(int x, int y)
{
this.Width = x;
this.Height = y;
if (x != y)
this.Height = this.Width;
}
public Square(int xy)
{
this.Width = xy;
this.Height = this.Width;
}
public override double ComputeArea(double _Area)
{
return _Area = this.Width * this.Height;
}
}
}
Yes, my csv file was slitted with semicolon. Im really glad you find the cause of the problem. This is only best for you, because this way you will learn the most. And do not forget to use Breakpoints (always), if you dont use them already.
Now you habe to figue out what exactly do you get into some variables. Of course you will get this error, if the value is not an integer (full number, with no decimals, and no string at all).
The code we will provide you, it will never work for 100%, until you will not understand the concept of the code. Until then, its worthless. There will always be something that it will interupt your code.
I cannot help you here, especiually because the code I gave you, it WAS WORKING 100%, and now you are saying its not working. Well then its not working. Find out why its not working. Spend some 10s of hours on the project and find out what is the matter. You are the one who has to understand the code here, and faster you will get it, better you you will be - believe me.
So, back to your issue:
As said. the value that is now in the "lineValues[j]" it is NOT an integer. You find out how its possible that some other type of value came into it. It surely is not my exmaple code you gave me, otherwise this wouldn`t have happened.
Man, again and again. One question for 2 weeks now. Please get some books and start learing by your self. We cannot teach you all here. We are here to help, not to teach ppl.
I wont answer on these kind of threads any longer. I think I gave given you more then enough, and if you still havent figured it out by now, this is not my problem. Sorry for sounding a bit harsh, but I simply dont like the way you are "forcing" us to do all the code you need instead of you.
bye
If you want to pass the value from form1 to form2 when the form2 is opened, you can use this kind of code:
//form1:
public partial class Form1 : Form
{
Form2 f2;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (f2 == null)
f2 = new Form2();
f2.ValueFromForm1(textBox1.Text);
f2.Show();
}
}
//form2:
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public void ValueFromForm1(string value)
{
textBox1.Text = value;
}
}
You do:
//form1:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2(textBox1.Text);
f2.Show();
}
}
//form2:
public partial class Form2 : Form
{
public Form2(string value)
{
InitializeComponent();
textBox1.Text = value;
}
}