|
Set up an event in form2 that form1 subscribes to. Either pass the data via a custom EventArgs with the event, or via a property on form2.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
The principal is demonstrated here[^], just adapt it to suit your situation.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
how to access the "format object" in crystal report in coding!
i wanna to change the font of parameter of crystal reports dynamically or at runtime !
and good solution !?
Something like :
repPreview1.ParameterFields["Name"].Font= ...
|
|
|
|
|
I am seeking a way to Convert pixels to Twips ?
any good solution.
I have searched google but no used ans i get!
|
|
|
|
|
If you Bingle pixels to twips you will find loads of examples.
If you have done so and are unable convert the examples to C#, that is another matter.
Ask for help on the specific problems you are having and someone may be able to help you.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Henry Minute wrote: Bingle
That's a new term, but doesn't have the verb/noun impact as Google
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
You stand corrected.
Gingle not Bingle is the new term. It has the impact!
|
|
|
|
|
This[^] suggests all it takes is multiplying by 14.40
|
|
|
|
|
Hello,
I am developing a GMAO csharp smart device application.I am in the step of creating a checklist using checkbox tool added dynamically:
I have two tables:Travaux (Works in English) and Actions related by the two fields Nature (table Travaux)and typeTravail(Table Actions).If the user enters the number of the work(NBT the pk_Travaux),the system adds a number of checkboxs equal to the steps that should the user follows to accomplish(field step in Actions table).After that,the user has the possibility to check or not the step if he did it.All the traitments will be done dynamically with the database
My select statement is:
select Etape from Action where ((Travaux.NBT=textbox1.text) and (Travaux.Nature=Action.TypeTravail))
Equal of what this select returns,it will add dynamically checkboxs
I tried with this code but not working due to some errors
private void button1_Click(object sender, EventArgs e)
{
string wCS = @"Data Source =\Storage Card\ModeDifféré\BaseGmaoLocale.sdf;";
SqlCeConnection sqlceconn = new SqlCeConnection(wCS);
SqlCeCommand command = sqlceconn.CreateCommand();
command.CommandText = "Select NBT, Nature from Travaux where NBT=@NBT ";
string s1 = textBox1.Text;
SqlCeParameter NBT = new SqlCeParameter("@NBT", SqlDbType.NVarChar);
NBT.Value = s1;
command.Parameters.Add(NBT);
SqlCeDataAdapter adapter = new SqlCeDataAdapter(command);
DataSet ds = new DataSet();
try
{
adapter.Fill(ds, "SQL Temp Table");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
foreach (DataRow da in adapter)
{ string s = adapter["Nature"]; }
if ((ds.Tables.Count > 0) && (ds.Tables["SQL Temp Table"] != null))
{
MessageBox.Show("Number of row(s) - " + ds.Tables["SQL Temp Table"].Rows.Count);
if (ds.Tables["SQL Temp Table"].Rows.Count > 0)
{
MessageBox.Show("Numéro de BT trouvé");
SqlCeCommand command1 = sqlceconn.CreateCommand();
command1.CommandText = "Select NoEtape, Etape from Travaux where TypeTravail=@typ ";
string s2 = textBox1.Text;
SqlCeParameter Typ = new SqlCeParameter("@Typ", SqlDbType.NVarChar);
Typ.Value = s2;
command1.Parameters.Add(Typ);
SqlCeDataAdapter adapt = new SqlCeDataAdapter(command1);
DataSet dat = new DataSet();
try
{
adapt.Fill(dat, "SQL Temp Table");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
foreach (DataRow ligne in adapt.)
{
System.Console.WriteLine(adapt[0]);
}
}
else MessageBox.Show("Veuillez saisir un autre NBT");
}
adapter.Dispose();
sqlceconn.Dispose();
command.Dispose();
}
The errors are :
Error 1 foreach statement cannot operate on variables of type 'System.Data.SqlServerCe.SqlCeDataAdapter' because 'System.Data.SqlServerCe.SqlCeDataAdapter' does not contain a public definition for 'GetEnumerator' C:\Users\Admin\Documents\Visual Studio 2008\Projects\GMAOMobile\ModeDifféré\Travail.cs
Error 2 Cannot apply indexing with [] to an expression of type 'System.Data.SqlServerCe.SqlCeDataAdapter' C:\Users\Admin\Documents\Visual Studio 2008\Projects\GMAOMobile\ModeDifféré\Travail.cs
Error 3 foreach statement cannot operate on variables of type 'System.Data.SqlServerCe.SqlCeDataAdapter' because 'System.Data.SqlServerCe.SqlCeDataAdapter' does not contain a public definition for 'GetEnumerator' C:\Users\Admin\Documents\Visual Studio 2008\Projects\GMAOMobile\ModeDifféré\Travail.cs
Error 4 Cannot apply indexing with [] to an expression of type 'System.Data.SqlServerCe.SqlCeDataAdapter' C:\Users\Admin\Documents\Visual Studio 2008\Projects\GMAOMobile\ModeDifféré\Travail.cs
I wait for u help
Thanks
|
|
|
|
|
Tunisien86 wrote: foreach (DataRow da in adapter) { string s = adapter["Nature"]; }
Should be
foreach (DataRow da in ds.Tables[0].Rows)
{
string s = da["Nature"];
}
Tunisien86 wrote: foreach (DataRow ligne in adapt.) { System.Console.WriteLine(adapt[0]); }
This should be
foreach (DataRow dataRow in dat.Tables[0].Rows)
{
System.Console.WriteLine(dataRow[0]);
}
|
|
|
|
|
Hi,
Thanks Reddy,the errors disappears all with some corrections:
foreach (DataRow da in ds.Tables[0].Rows)
{
string s = da[0].ToString();}
.I want now to add every row it found after executing the select request:
command1.CommandText = "Select NoEtape, Etape from Action where TypeTravail=@typ ";
I create a listview and I wanna add like items every result of the select.I modify my code in his end like this:
............
foreach (DataRow dataRow in dat.Tables[0].Rows)
{
ListViewItem item = new ListViewItem();
item.Text = dataRow[0].ToString();
listView1.Items.Add(item);
System.Console.WriteLine(dataRow[0]);
}
}
else MessageBox.Show("Veuillez saisir un autre NBT");
}
adapter.Dispose();
sqlceconn.Dispose();
command.Dispose();
}
}
But this modification doesn't show any thing in the listviewitem.
Thanks a lot for u suggestions
|
|
|
|
|
Tunisien86 wrote: dat.Tables[0].Rows
Did you check if the DataTable has any rows after executing the select statement? Does it even get into the foreach loop?
|
|
|
|
|
Hi,
Thank u for u help.I found the solution using the listview tool(with its option checked) and all gets well.This is the link after that solved my issue:
http://msdn.microsoft.com/en-us/library/ms229643.aspx[^]
Thanks a lot and can u have a look to my new thread:DataGridView-DataBase in csharp smart device posted a few minutes ago
Thanks
|
|
|
|
|
Hi, I have the following string "455.56"
I want this to format in: 00455.5600.
I tried this and was expecting it to work fine: string strLong = String.Format(CultureInfo.InvariantCulture, "{0:00000.0000}", "455.66");
This statement results in: "455.66"!!
Why doesn't this work as expected? Other solutions?
thanks for your time.
Regards,
Jan
|
|
|
|
|
Try feeding it a number rather than a string...
string strLong = String.Format(CultureInfo.InvariantCulture, "{0:00000.0000}", 455.66);
The format info :00000.0000 is for numeric formats only: MSDN String.Format formats[^]
[edit]Should have explained the format is numeric... Oops![/edit]
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Thanks for the answer, however
I did fed it a number also like this
String.Format(CultureInfo.InvariantCulture, "{0:00000.0000}", 455.66);
But the point is that the data to be formatted is in a string[] and even when I convert the string first to a double or whatever the result is the same, even the conversion is giving funky results: 45566 instead of 455.66!! I am not sure but I must be doing something stupid probably.
|
|
|
|
|
To do this while keeping it as a string will be messy:
string x = "456.78";
string[] parts = x.Split('.');
string whole = parts[0];
string decpart = parts[1];
string y = new string('0', 5 - whole.Length) + whole;
string z = decpart + new string('0', 4 - decpart.Length);
string padded = y + "." + z;
And that has no error checking!
To convert to double and back is probably the best way:
string x = "456.78";
double d = double.Parse(x, System.Globalization.CultureInfo.InvariantCulture);
string padded = string.Format("{0:00000.0000}", d);
But you will have to be absolutely sure that your number strings are all in "nnn.nn" format - remember that some cultures use "nnn,nn" which would bolox you right up! (That may be why your conversion gave funky results...)
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
I'd use a Regular Expression to perform the split.
|
|
|
|
|
I thought of doing it via Linq to SQL and a stored procedure, but decided it was too much typing...
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
I would think your small intestine would leap up your throat and throttle your brain if you tried that.
|
|
|
|
|
Yeah, but it'd be worth it - I could post it to "Coding Horrors"
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
jkpieters wrote: Why doesn't this work as expected?
Because it's a string rather than a number?
jkpieters wrote: Other solutions?
0) Don't have it as a string (parse it if necessary ).
1) Use PadLeft and PadRight.
2) Perhaps use my ApplyFormat[^].
System.Console.WriteLine ( "455.56".ApplyFormat ( "/10,10,0:" ) ) ;
But getting the decimal points to line up might be tricky in some cases.
|
|
|
|
|
Not sure if this is what you mean but try this:
string strLong = String.Format(CultureInfo.InvariantCulture, "{0:00000.0000}", Double.Parse("455.66", CultureInfo.InvariantCulture));
|
|
|
|
|
I hope you don't get any negative numbers...
|
|
|
|
|
They're strings, not numbers.
|
|
|
|