|
I found an MSDN article "KB302902" that explain how to use excel with late binding, but running the code at runtime, IDE generate an exception at the line:
//Add a new workbook.
objBook = objBooks.GetType().InvokeMember( "Add", BindingFlags.InvokeMethod, null, objBooks, null );
This happen on excel 2003 (os winXP), the same code on office XP (win2k) work properly.
Any ideas to solve problem?
Thanks a lot.
marco
|
|
|
|
|
Excel automation code fails in non-English Standard and Formats
To bypass problem, use the "en" culture using an overloaded signature.
Excel accepts the call without the runtime error, sample code:
....
System.Globalization.CultureInfo cultInfo = new System.Globalization.CultureInfo("en");
Type objClassType = Type.GetTypeFromProgID("Excel.Application");
object objApp = Activator.CreateInstance(objClassType);
object objBooks = objApp.GetType().InvokeMember( "Workbooks", BindingFlags.GetProperty, null, objApp, null, cultInfo);
object objBook = objBooks.GetType().InvokeMember( "Add", BindingFlags.InvokeMethod, null, objBooks, null, cultInfo);
object objSheets = objBook.GetType().InvokeMember( "Worksheets", BindingFlags.GetProperty, null, objBook, null, cultInfo);
object[] Parameters = new Object[1];
Parameters[0] = 1;
object objSheet = objSheets.GetType().InvokeMember( "Item", BindingFlags.GetProperty, null, objSheets, Parameters, cultInfo);
...
marco
|
|
|
|
|
Hi there
I am using a viewer panel (a class that i find in codeproject). This class gave me the opportunity to put a larger image in a panel with autoscroll bar. Now I want to made a function that give me the place where is the mouse when I click in this panel.
THe problem is when i click on the panel nothing happens =/
In my point of viem what is happening is the folowing, I have an image on the panel, so I made my click on the image and not on the panel.
How can I solve this? I just what to make a messagebox to appear when i click in a point of the panel.
Thanks, Sérgio
|
|
|
|
|
Doesn't the class have a Click event? If you don't know where to look for, open the panel in Forms Designer, right click and click Properties. Look for the lightning bolt icon in the toolbar of the Properties pane and click it. You should now see the events exposed by that control.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Apologies if this is a really simple question but I am baffled
I am experimenting with mobile apps and web services in my ongoing quest (no training budget, no manuals, no books) to learn C#.NET
I have an app that reads data from a web service - I can do that What I want to do is store this data so it is available for all other forms to access when I open them up. My main form gets the webservice data on form_load, I then have a button that opens form2 and I would like form2 to be able to fill its listbox with the webservice data previously read in form1. Form3 is activated in a similar way from form2 so i have a chain of forms all wanting to show the data in their own controls - listbox, domainupdown, multiline text boxes etc.
In my previous life of VB hackery and bodgery I could just have a global array accessible from any form - I cant seem to do that in C# but I am sure there must be an easy way with classes - I just don't know it - VB has messed up my mind
Thanks in advance.
I still remember having to write your own code in FORTRAN rather than be a cut and paste merchant being pampered by colour coded Intellisense - ahh proper programming - those were the days
|
|
|
|
|
It is possible to have a static property in your main form, like
<br />
public class MainForm : Form<br />
{<br />
private static int data;<br />
<br />
public void FetchDataFromWebService()<br />
{<br />
data = webService.GetData();<br />
}<br />
<br />
public static int Data<br />
{<br />
get { return data; }<br />
}<br />
}<br />
Of course, you can make the data member public, but exposing it via a property is recommended. Or, if your main form is the one that creates all other forms, how about passing it along to others instead of maintaining it in the main form?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Does anyone know how to do The Critter Program from Andy Harris book's on the the challenge questions page 128.
Please help me for the solution...Thanx a million!
|
|
|
|
|
|
The Critter Program
using System;
namespace Critter {
///
/// Critter
/// Demonstrates basic OOP principles including properties and methods
/// Andy Harris, 12/13/01
///
class Menu {
static void Main(string[] args) {
bool keepGoing = true;
int choice;
Critter myCritter = new Critter();
myCritter.name = "George";
while (keepGoing){
myCritter.age();
choice = showMenu();
switch (choice){
case 0:
keepGoing = false;
break;
case 1:
Console.WriteLine(myCritter.talk());
break;
case 2:
myCritter.eat();
Console.WriteLine ("You have fed the critter");
break;
case 3:
myCritter.play();
Console.WriteLine("You have played with the critter");
break;
case 4:
Console.WriteLine("Current name: {0}", myCritter.name);
Console.Write("Change name to: ");
myCritter.name = Console.ReadLine();
break;
default:
Console.WriteLine("That was not a valid input");
break;
} // end switch
} // end while loop
} // end main
static int showMenu(){
int input = 1;
Console.WriteLine();
Console.WriteLine();
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("0) Exit");
Console.WriteLine("1) Listen to Critter");
Console.WriteLine("2) Feed Critter");
Console.WriteLine("3) Play with Critter");
Console.WriteLine("4) Rename Critter");
try {
input = Convert.ToInt32(Console.ReadLine());
} catch (FormatException) {
Console.WriteLine("Incorrect input");
} // end try
return input;
} // end showMenu
} // end class
class Critter {
private string pName;
private int pFull = 10;
private int pHappy = 10;
private int pAge = 0;
public string name {
get {
return pName;
} // end get
set{
if (value.Length > 8){
Console.WriteLine("The name can't be more than 8 characters");
pName = value;
pName = pName.Substring(0,8);
Console.WriteLine("Changing name to {0}", pName);
} else {
pName = value;
} // end if
} // end set
} // end string property
public string talk(){
string message;
message = "The critter says: \n";
if (pHappy > 5) {
message += " Hi! My name is " + name + "\n";
message += " I feel happy today! \n";
} else if (pHappy > 2) {
message += " " + name + " doesn't feel so good...";
} else if (pHappy > 0) {
message += " " + name + " is MAD...";
} else {
message += " ...nothing at all, but lays in a heap.";
} // end if
return message;
} // end talk
public void age(){
//handles aging the critter
pAge++;
pFull--;
pHappy--;
if (pFull < 3) {
//if hungry, accellerate unhappiness
pHappy--;
} // end if
} // end age
public void play(){
pHappy += 3;
} // play
public void eat(){
pFull += 4;
} // end eat
} // end class
} // end namespace
I dunno how to attach from here, just copy n paste what i have done so far (i've done 3 out of )...but theres more questions:
-modify the program so that is shows the critter's age. special reward to the owner who can keep a critter happy.
-add another method to the critter, such as sleep()
-add cas variable, when you fed the critter the money will be drecrease
Thanks a million
|
|
|
|
|
Yeah, there may be 1.8 million users of CodeProject, but 99.9% of them don't check up on the board every single day. So the chances of finding a person who has that book are very slim to none.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
Is it possible to change form title bar or caption bar color in c# without changing the windows setting?
How do I do that to a specific form?
Please guide.
Thanks,
Nitu
|
|
|
|
|
This can only happen if you override the form's WndProc and handle the WM_NCPAINT message. You might want to take a look at this[^] for a little more information on overriding WndProc.
[EDIT]
I should have said, "handle the WM_NCPAINT message and draw the non-client area of the form yourself."
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi Dave,
Thanks for your prompt reply . I'll check that out.
Regards,
Nitu
|
|
|
|
|
hello.im doin a projecton fingerprint recognition using C#.i have very little knowledge about image processing. could i get some help on this.
thank you.
ash
|
|
|
|
|
|
|
i have to transpose the row and column in any dataTable dynamically. i.e. if we add any row in the table it should display as the new column.
Thanks and Regards
Vinay Kumar
Perot Systems,
Bangalore, India.
|
|
|
|
|
hi
i have a directed graph.
i want to know when delete vertex_A from graph , should i join all childs of vertex_A to each parent of vertex_A or not?
thanks.
|
|
|
|
|
Erm, it depends on what behaviour you want from your graph. 'Normal' behavior would be to leave it as it is.
Ryan
Ryan.
|
|
|
|
|
Hi csharper's,
I am using automation to control MS Word with C#.
Does someone know if Word (Office) have a busy flag to test for to prevent a close command before work (printing) is done ?
Thank you
Frank
fracalifa
|
|
|
|
|
The problem is weird. I make a call to the method that does the binding. The method executes once, but it terminates after the databinding statement (not the close statements) then returns back to the Page_load method. This causes a problem because the connection is still open from the first time through. The html page with the dropdown list never appears.
If you can help great!
public class SA_ArptSelNav : System.Web.UI.Page<br />
{<br />
protected System.Web.UI.WebControls.ImageButton ZoomInButton1;<br />
protected System.Web.UI.WebControls.ImageButton ZoomOutButton1;<br />
protected System.Web.UI.WebControls.ImageButton ZoomPrevButton1;<br />
protected System.Web.UI.WebControls.ImageButton ZoomExtButton1;<br />
protected System.Web.UI.WebControls.ImageButton PanButton1;<br />
protected System.Web.UI.WebControls.ImageButton PrintButton1;<br />
protected System.Web.UI.WebControls.DropDownList DropDownList1;<br />
protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;<br />
protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;<br />
protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;<br />
protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;<br />
protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;<br />
protected System.Data.OleDb.OleDbConnection oleDbConnection1;<br />
protected dbListOfAirports dbListOfAirports1;<br />
protected System.Web.UI.WebControls.ImageButton CopyButton1;<br />
<br />
private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
if (!Page.IsPostBack) <br />
{<br />
BindListToDropDown();<br />
}<br />
}<br />
<br />
#region Web Form Designer generated code<br />
override protected void OnInit(EventArgs e)<br />
{<br />
InitializeComponent();<br />
base.OnInit(e);<br />
}<br />
<br />
private void InitializeComponent()<br />
{ <br />
this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();<br />
this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();<br />
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();<br />
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();<br />
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();<br />
this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();<br />
this.dbListOfAirports1 = new dbListOfAirports();<br />
((System.ComponentModel.ISupportInitialize)(this.dbListOfAirports1)).BeginInit();<br />
this.DropDownList1.DataBinding += new System.EventHandler(this.Page_Load);<br />
this.oleDbDataAdapter1.DeleteCommand = this.oleDbDeleteCommand1;<br />
this.oleDbDataAdapter1.InsertCommand = this.oleDbInsertCommand1;<br />
this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;<br />
this.oleDbDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {<br />
new System.Data.Common.DataTableMapping("Table", "tblAirport", new System.Data.Common.DataColumnMapping[] {<br />
new System.Data.Common.DataColumnMapping("AirportCode", "AirportCode"),<br />
new System.Data.Common.DataColumnMapping("AirportID", "AirportID"),<br />
new System.Data.Common.DataColumnMapping("AirportName", "AirportName"),<br />
new System.Data.Common.DataColumnMapping("City", "City"),<br />
new System.Data.Common.DataColumnMapping("Latitude", "Latitude"),<br />
new System.Data.Common.DataColumnMapping("Longitude", "Longitude"),<br />
new System.Data.Common.DataColumnMapping("State", "State")})});<br />
this.oleDbDataAdapter1.UpdateCommand = this.oleDbUpdateCommand1;<br />
this.oleDbDeleteCommand1.CommandText = "DELETE FROM tblAirport WHERE (AirportID = ?)";<br />
this.oleDbDeleteCommand1.Connection = this.oleDbConnection1;<br />
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_AirportID", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "AirportID", System.Data.DataRowVersion.Original, null));<br />
this.oleDbConnection1.ConnectionString = @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=0;Data Source=""D:\MGDevelopment\SIMDAC Viewer\DB\simdac_be.mdb"";Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1";<br />
this.oleDbInsertCommand1.CommandText = "INSERT INTO tblAirport(AirportCode, AirportName, City, Latitude, Longitude, State" +<br />
") VALUES (?, ?, ?, ?, ?, ?)";<br />
this.oleDbInsertCommand1.Connection = this.oleDbConnection1;<br />
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("AirportCode", System.Data.OleDb.OleDbType.VarWChar, 4, "AirportCode"));<br />
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("AirportName", System.Data.OleDb.OleDbType.VarWChar, 50, "AirportName"));<br />
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("City", System.Data.OleDb.OleDbType.VarWChar, 20, "City"));<br />
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Latitude", System.Data.OleDb.OleDbType.VarWChar, 50, "Latitude"));<br />
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Longitude", System.Data.OleDb.OleDbType.VarWChar, 50, "Longitude"));<br />
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("State", System.Data.OleDb.OleDbType.VarWChar, 2, "State"));<br />
this.oleDbSelectCommand1.CommandText = "SELECT AirportCode, AirportID, AirportName, City, Latitude, Longitude, State FROM" +<br />
" tblAirport";<br />
this.oleDbSelectCommand1.Connection = this.oleDbConnection1;<br />
this.oleDbUpdateCommand1.CommandText = "UPDATE tblAirport SET AirportCode = ?, AirportName = ?, City = ?, Latitude = ?, L" +<br />
"ongitude = ?, State = ? WHERE (AirportID = ?)";<br />
this.oleDbUpdateCommand1.Connection = this.oleDbConnection1;<br />
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("AirportCode", System.Data.OleDb.OleDbType.VarWChar, 4, "AirportCode"));<br />
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("AirportName", System.Data.OleDb.OleDbType.VarWChar, 50, "AirportName"));<br />
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("City", System.Data.OleDb.OleDbType.VarWChar, 20, "City"));<br />
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Latitude", System.Data.OleDb.OleDbType.VarWChar, 50, "Latitude"));<br />
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Longitude", System.Data.OleDb.OleDbType.VarWChar, 50, "Longitude"));<br />
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("State", System.Data.OleDb.OleDbType.VarWChar, 2, "State"));<br />
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_AirportID", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "AirportID", System.Data.DataRowVersion.Original, null));<br />
this.dbListOfAirports1.DataSetName = "dbListOfAirports";<br />
this.dbListOfAirports1.Locale = new System.Globalization.CultureInfo("en-US");<br />
((System.ComponentModel.ISupportInitialize)(this.dbListOfAirports1)).EndInit();<br />
<br />
}<br />
#endregion<br />
<br />
private void BindListToDropDown()<br />
{<br />
oleDbConnection1.Open();<br />
OleDbDataReader OleDbReader = this.oleDbSelectCommand1.ExecuteReader(CommandBehavior.CloseConnection);<br />
DropDownList1.SelectedIndex=0;<br />
DropDownList1.DataSource=OleDbReader;<br />
DropDownList1.DataBind();<br />
<br />
OleDbReader.Close();<br />
oleDbConnection1.Close();<br />
}<br />
}
|
|
|
|
|
Hi Everyone!
I make a Webform1.aspx which contains an web user control. In Microsoft IE it can viewed perfectly, but in Mozilla for example, some property can not run properly. For example, when i hide a some control on my web form when it run on Mozilla, all control is visible. I don't know reason why and how can fix it ?
Đào Ngọc Hào! Hi How Are You?
|
|
|
|
|
Hi,
I 've a function which takes 2 parameters, a dataset , path to XSD file. Based on contents of the xsd file i need to modify data in daatset to generate appropriate xml.How do I do this?
Thanks in advance
Priya
|
|
|
|
|
Hi Dpriya,
Guess the following code will give you an idea to solve the above problem.
The following code will take a XML file as the datasource(abc.xml) and will generate another xml file (abc234.xml) based on the schema (Test.xsd).
DataSet ds;
XmlDataDocument ddc = new XmlDataDocument();
ds = ddc.DataSet;
ds.ReadXmlSchema(@"Test.xsd");
ddc.Load(@"abc.xml");
ds.WriteXml(@"abc234.xml");
Hope this will help you.
Thanks and Regards
SGS
|
|
|
|
|
Hi
I extended a textbox control and created a property i.e
public enum myVarEnum {Apple,Mango,Peach};
protected myVarEnum myvar1;
public myVar MyProperty
{
get { return myvar1; }
set { myvar1 = value; }
}
Now when i use this extended control i am getting the property as a dropdown and i am able to select, the problem is the value i select doesnot persist..for example if i select "Mango" it goes back to the first one "Apple" after i build the solution. i guess its a small mistake plz help me overcome this...
Regards
Deepak.S
|
|
|
|
|