|
This is the purpose of events, the same method that is used to communicate between all controls and their parents. Harvey has already linked to his article - there are many around including mine here[^].
This is a ready made demo app that shows child to parent communication passing data in the event args.
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ChildToParentDemo
{
public partial class FormParent : Form
{
private Button buttonShowChild;
public FormParent()
{
InitializeComponent();
buttonShowChild = new Button();
buttonShowChild.Text = "&Show Child";
buttonShowChild.Location = new Point(12, 12);
Controls.Add(buttonShowChild);
AcceptButton = buttonShowChild;
buttonShowChild.Click += buttonShowChild_Click;
}
private void buttonShowChild_Click(object sender, EventArgs e)
{
FormChild formChild = new FormChild();
formChild.StringData += formChild_StringData;
formChild.ShowDialog(this);
formChild.Dispose();
}
void formChild_StringData(object sender, StringDataEventArgs e)
{
MessageBox.Show(e.StringData);
}
}
}
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ChildToParentDemo
{
public partial class FormChild : Form
{
public event EventHandler<StringDataEventArgs> StringData;
private Button buttonBroadcastData;
private TextBox textBoxStringData;
public FormChild()
{
InitializeComponent();
textBoxStringData = new TextBox();
textBoxStringData.Location = new Point(12, 12);
buttonBroadcastData = new Button();
buttonBroadcastData.Text = "&Broadcast Data";
buttonBroadcastData.Location = new Point(124, 12);
Controls.AddRange(new Control[]
{ textBoxStringData, buttonBroadcastData });
AcceptButton = buttonBroadcastData;
buttonBroadcastData.Click += buttonBroadcastData_Click;
}
private void buttonBroadcastData_Click(object sender, EventArgs e)
{
OnStringData(new StringDataEventArgs(textBoxStringData.Text));
}
protected virtual void OnStringData(StringDataEventArgs e)
{
EventHandler<StringDataEventArgs> eh = StringData;
if (eh != null)
eh(this, e);
}
}
}
using System;
namespace ChildToParentDemo
{
public class StringDataEventArgs : EventArgs
{
private string stringData;
public StringDataEventArgs(string stringData)
{
this.stringData = stringData;
}
public string StringData
{
get { return stringData; }
}
}
}
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Once a user clicks in the grid the cell is selected. If they then select the entire row, pressing Delete deletes the contents of the selected cell, not row?
Is there a way round that?
|
|
|
|
|
depends on what your current sourcecode situation is
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
Managed it this way
private void dgvOrders_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
Validate();
BindingContext[dsOrders, "Orders"].EndCurrentEdit();
dgvOrders.Rows[e.RowIndex].ErrorText = "";
}
But going to ask another question - if CellValidating has raised an error, how do I cancel that.
|
|
|
|
|
This is a very difficult question to search for.
Grid is in VirualMode. Bound to a DataSet. I have tables for the extra columns.
Grid size adjusted for number of rows.
Grid starts off empty.
On UserAddedRow I add a row to the tables.
On UserDeletedRow I remove that row from the tables.
The user starts typing in empty row. UserAddedRow triggered. Extra rows in tables added.
Now user presses Esc. Row removed from grid.
How do I catch that?
I am using RowsRemoved and checking for the tables not null and comparing number of rows in the grid to rows in the table in order to decide to delete rows in the tables and resize the grid.
Surely there is an easier way than that?
|
|
|
|
|
hi,
I want to create a tool which is used to convert pdf to text.Please provide some guidelines and code to do this project.
Thank you,
prem
|
|
|
|
|
|
Hello
I'm working on writing code that the retailer
C #. Net
I want to print an invoice directly when you save a sales invoice, which I've created the report has been the emergence of all the details desired in the report and after the appearance of the report I print it through the land cover on the button of your printer in the report is already in
MicroSoft.Reporting.WinForms.ReportViewer
And a data source by the name of the report
SaleReport.rdlc
And a source of design through
SalesDataSet.xsd
I Bouklgaha in the system through the addition of
Add NewItem
But after arriving in this class I want to print the report directly from that I am not pressing any button on the screen without opening the screen that Tardhaltgarir
How can I print this way without the emergence of direct ReportViewer
I am sorry if they write English is poor
Thaer
|
|
|
|
|
There's a walkthrough by Microsoft here[^], explaining how to print a report without showing it.
Good luck
I are Troll
|
|
|
|
|
Hello
Thank you for the help
But this is not what I want because: the source of the database is not an existing file, but I have to create
DataSet
In the system and you put a source of the report and the report shows all the details that I want to
But what I want is to print directly now
Thaer
|
|
|
|
|
Thaer Hamael wrote: you put a source of the report and the report shows all the details
A generic report that shows whatever data that you point to? That would require you to generate the RDL[^] at runtime.
Happy Programming
I are Troll
|
|
|
|
|
Dear all,
I have a application that writes some data to excel sheet. Ofter installing my application on a PC with no Office, when i run it, im getting this error:
System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154.
at QeKms.Classes.Export.ExportToExcel(DataTable dt, String path)
at QeKms.Classes.Export.ExportData()
The Microsoft.Office.Interop.Excel.dll is included in the application directory.
What is this error mean? Do i have to install MS Office on each computer before running my application?
Thanks in advance
|
|
|
|
|
Office.Interop.Excel works by invisibly opening a copy of excel in the background to perform the work - just as you would expect.
So yes, you do need Office (or at least the correct version of excel) installed on every machine your software is going to run on.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Thanks for response.
Are you sure about that? Do i have to really install ms excel in all machines where i want to run my app?
|
|
|
|
|
Sorry about the delay in replying, but if you had posted it as a reply to my message, rtaher than yours, I would have got an email to tell me there was a reply! By luck I saw this, so can answer...
Yes. You have to have Excel installed on every machine that you want to run your app on, if your app uses Interop.Excel. You will get an exception otherwise (as you have seen!)
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Dear OriginalGriff,
Thanks a lot, now i know more about it
|
|
|
|
|
Hi,
I want to show multiple records on form. I dont want to use grid view..
I want to display records like showing lable on row..
Is there any repeater control like control in windows application.
Any other solution ?
Thanks
sjs
|
|
|
|
|
Obviously, there is nothing like this in Windows forms. But you can
create a control to achieve your goal. You just need to dynamically add
more controls for each row in your data.
Also you can check this: http://www.ewoodruff.us/EWSListControls.aspx
modified 27-May-14 4:57am.
|
|
|
|
|
Hi,
I am using regextest program and filtering out text using below regex
(?<=\<div class="middleadimggold"\>).*?(?=\</div\>)
now I would like to include this in my c# code so that i can write only the text that matches. I am unsuccessfully doing this by using below code. I think something is not right and its not filtering out the data.
string match = @"(?<=\<div class=""middleadimggold""\>).*?(?=\</div\>)";
using (StreamWriter sw = File.AppendText(@"c:\logs\data.txt"))
{
if (Regex.IsMatch(this.Text,match))
{
sw.WriteLine(this.Text);
sw.Close();
}
}
could someone please help. I think its something to do with inverted comma as when i ran the code in debug mode
match becomes
(?<=\\<div class=\"middleadimggold\"\\>).*?(?=\\</div\\>)
if I put above expression in the regex software nothing is being returned.
Thank you,
modified on Wednesday, January 13, 2010 12:36 AM
|
|
|
|
|
Pasted your code into my app, and removed the StreamWriter stuff (otherwise identical)
private void button1_Click(object sender, EventArgs e)
{
string text = tbPath.Text;
string match = @"(?<=\<div class=""middleadimggold""\>).*?(?=\</div\>)";
if (Regex.IsMatch(text, match))
{
MessageBox.Show(text);
}
}
It works for me if I paste
<div class="middleadimggold">Data</div> into the text box. The match works, and I get the message box - what doesn't happen with you?
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
it doesnt write the matching text to a file. so i do need streamwriter stuff working
|
|
|
|
|
Ok, but if teh Regex bit works her, then it will be working there. Which implies it is your file, streamwriter, or the data that is faulty.
Are you getting any exceptions?
Are you sure your data contains the match string?
Have you tried a MessageBox or similar to check the data and the Regex match?
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
does it works if there is a big space between <div class="middleadimggold"> and closing of ?
a typical example is as below:
<div class="middleadimggold">
<a href="bla">bla
notice the spaces after initial div
|
|
|
|
|
Ah! It's your data! Looking at at your other post, it isn't the big white space - it's the newlines. You need to make a small change to your app:
if (Regex.IsMatch(allRead, regMatch))
becomes:
if (Regex.IsMatch(allRead, regMatch, RegexOptions.Singleline))
Should fix it.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Remove '\', there is no need to use '\' before '>'.
modified 27-May-14 4:57am.
|
|
|
|