|
I was doing some final testing on a program that I build last week, when I encountered the following error in a databound datagridview
DataGridViewComboBoxCell value is invalid
It happend without a real reason, because nothing has changed since the last test and that last test succeeded without error.
Anybody have a clue as what might be going on here? I checked the databinding, but that seems correct to me. So it must be something else.
WM.
What about weapons of mass-construction?
|
|
|
|
|
I have a "Back" link in aspx page.
If clicked on this link it go to previouspage. For this I wrote back
It is working fine.
But I also Have a continue button which inserts data into db when clicked on it.
So If i go back and click on continue new record is inserte for the same member i don't want that to happen.
I want to maintain state persistence.
how can I do this.
Can Anybody help me
Thanx in Advance
chanti
|
|
|
|
|
This question belongs in the ASP.NET forum.
|
|
|
|
|
private void WhatFormToShow(Form f)
{
f.MdiParent = this;
f.Dock = DockStyle.Fill;
f.Show();
this.pnlCompositeCon.Controls.Clear();
this.pnlCompositeCon.Controls.Add(f);
this.txtCurrentLoadedForm.Text = f.Name.ToUpper();
}
WhatFormToShow(FrmAdd);
when i call the function i got this error, that said "its a 'type' but us used like a 'variable'...what is the proper way of doing this? please help
-- modified at 3:18 Saturday 14th October, 2006
|
|
|
|
|
What is the exact (!) error message you get?
The compiler won't tell you "its a 'type'". What is 'its'?
Could it be that FrmAdd is the name of your form class and not the name of a form instance?
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
All I can do is guesses.
I guess that you get the error at this line:
WhatFormToShow(FrmAdd);
and I guess that FrmAdd is a class name. Is this the case? If so you have to pass an object no a class to the method.
Regards
|
|
|
|
|
thanks for reply
Yup i want to pass the form class name so i can instantiate the form by using the function.
Im tired of typing...
FrmNew myF = new FrmNew();
myF.Show();
or if there are more form setting to setup.
i want to pass the form name so the function can create it and instantiate it automatically.
Im new to c# any links to enlighten me more on this subject please dont hesitate to point me to the right direction
Thanks
|
|
|
|
|
While you can achieve something like this using reflection, I strongly doubt that you should do it.
Giving "I'm tired of typing..." as the reason simply isn't enough. What are the advantages you get for the flexibility you lose?
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Well, you want to make some sort of a Froms factory!! This is possible, but as Mav said... Why?? Each form has its own special properties to be initialized. Why don't you initialize them at design time once??
Anyway, I'm not in the position to judge or modify your coding style. All I wanted was to guide you to what I think is better than what you want. Trust me, this isn't the reason to make such a factory method.
Anyway, you can do it -like Mav said again- using Reflection namespace.
1- Declare your method as
MyMethod(Type TheForm)
2- Call it as
MyMethod(typeof(FormClassName));
3- In the Form you can call Assembly.CreateInstance() to create your form. Then using this object you can initialize it.
Yet, again... Does it really worth all this??
Regards
|
|
|
|
|
I see. Thanks mav and nader
I really wanted to implement this as part of my UI. I have created an mdi application that mimic the MS MONEY 2006 tab bar
tab ---> HOME BILLING INVENTORY
So if i click on the HOME TAB, it will only load a single form. this is all done in my FrmMain. this is why i have this sub.
private void SelectTabToView(string sWhatTab)
{
switch (sWhatTab.ToUpper()) {
case "HOME":
FrmHome F1 = new FrmHome()
F1.MdiParent = this;
F1.Dock = DockStyle.Fill;
F1.Show();
this.pnlCompositeCon.Controls.Clear();
this.pnlCompositeCon.Controls.Add(F1);
this.txtCurrentLoadedForm.Text = F1.Name.ToUpper();
break;
case "BILLING":
FrmHome F2 = new FrmHome()
F2.MdiParent = this;
F2.Dock = DockStyle.Fill;
F2.Show();
this.pnlCompositeCon.Controls.Clear();
this.pnlCompositeCon.Controls.Add(F2);
this.txtCurrentLoadedForm.Text = F2.Name.ToUpper();
break;
case "INVENTORY":
FrmHome F3 = new FrmHome()
F3.MdiParent = this;
F3.Dock = DockStyle.Fill;
F3.Show();
this.pnlCompositeCon.Controls.Clear();
this.pnlCompositeCon.Controls.Add(F3);
this.txtCurrentLoadedForm.Text = F3.Name.ToUpper();
break;
}
}
So i could have used the function
private void SelectTabToView(string sWhatTab)
{
switch (sWhatTab.ToUpper()) {
case "HOME":
WhatFormToLoad(FrmHome);
break;
case "BILLING":
WhatFormToLoad(FrmBilling);
break;
case "INVENTORY":
WhatFormToLoad(FrmInventory);
break;
}
}
This is much easier than typing all those redundant settings
Thats why i have decide to create a generic routine or a form factory to catter the loading of forms by just passing the form name.
If im not on the right path in doing this please advice on what to do
Maybe i was just looking how to hammer a nail with a jackhammer
|
|
|
|
|
Well, you can use generics;P
Or much simpler, this:
private void SelectTabToView(string sWhatTab)
{
switch (sWhatTab.ToUpper()) {
case "HOME":
{
FrmHome frm = new FrmHome();
WhatFormToLoad(Frm);
break;
}
case "BILLING":
{
FrmBilling frm = new FrmBilling();
WhatFormToLoad(Frm);
break;
}
case "INVENTORY":
{
FrmInventory frm = new FrmInventory();
WhatFormToLoad(Frm);
break;
}
}
}
private void WhatFormToLoad(Form MyForm)
{
MyForm.MdiParent = this;
MyForm.Dock = DockStyle.Fill;
MyForm.Show();
this.pnlCompositeCon.Controls.Clear();
this.pnlCompositeCon.Controls.Add(MyForm);
this.txtCurrentLoadedForm.Text = MyForm.Name.ToUpper();
}
Regards
|
|
|
|
|
Thanks for the Prompt reply, nader
I was about to go on this direction. As i was playing with the Refactoring menu
anyway thanks for the input its highly appreciated
|
|
|
|
|
hey whats up? i need help! i query a database off a web site and i onnly want a few fields, this is in c#..
this db has thousands of records which is why i need to code this. this is just to make a contact list.
what i want is:
Pastor/Leader: John Cowan
Contact Info: phone: 916-387-9750
Mailing Address: 7322 Folsom Blvd, Sacramento, CA 95826 USA
Website: http://www.calvarysac.org/
html is:
body {margin ; font-family:"lucida grande", tahoma, arial, verdana, sans-serif; font-size:10px}
label {display: block; font: normal 10px/16px "lucida grande", tahoma, arial, verdana, sans-serif; margin: 0; padding: 0px 0; color: #666;}
.textfield {font: normal 11px/13px "lucida grande", tahoma, arial, verdana, sans-serif; padding:2px; margin: 0; border: 1px solid #ccc; background-color: #eee; width: 100%; color: #666;}
.textfield2 {font: normal 11px/13px "lucida grande", tahoma, arial, verdana, sans-serif; padding:2px; margin: 0; border: 1px solid #ccc; background-color: #eee; width: 207px; color: #666;}
#contact td {padding:5px;}
#contact table {width: 100%;}
h1 {margin ; padding ; font-size:20px; margin-bottom:7px}
div.hr {height: 2px; background: #ddd; margin:10px 0 7px 0 }
div.hr hr {display: none;}
a {color:#374872}
a:visited {color:#374872}
a:hover {background:#ddd}
#verified p span {padding:3px}
/* Images */
img {border: none;}
p.img {margin: 0; padding: 0;}
p.img img {float: right; margin: 0 0 1em 1em;}
p.img a img {padding: 3px; border: 1px solid #c4c4c2;}
p.img a:hover img {border: 1px solid #949492;}
Calvary Chapel Sacramento
Pastor/Leader: John Cowan
Contact Info:
phone: 916-387-9750
facsimile: 916-387-9752
Mailing Address:
7322 Folsom Blvd.
Sacramento, CA 95826 USA
Meeting Address:
7322 Folsom Blvd.
Sacramento, CA 95826 USA
★ View Map
Website: http://www.calvarysac.org/
//<![CDATA[
if(typeof sIFR == "function"){
sIFR.replaceElement(named({sSelector:"h1", sFlashSrc:"/assets/swf/avenir.swf", sColor:"#374872", sLinkColor:"#000000", sBgColor:"#FFFFFF", sHoverColor:"#CCCCCC", nPaddingTop , nPaddingBottom , sFlashVars:"textalign=left&offsetTop=0"}));
};
//]]>
|
|
|
|
|
Hello. Is it possible to create controls from a textfile?
For example, my text file contains:
Panel pNew = new Panel();
pNew.BackColor = System.Drawing.SystemColors.ControlLightLight;
pNew.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
pNew.Location = new System.Drawing.Point(3, 5);
pNew.Name = "panel1";
pNew.Size = new System.Drawing.Size(368, 408);
pNew.AutoScroll = true;
How do I go about it?
|
|
|
|
|
Hello
Well, to some extent Yes! It's possible, but depends on:
1- What are you storing in your text file? Are you storing other parameters like the location, size, etc...??
2- Do you know exactly what you are storing in the text file? ie. All the controls hve the same format, or do some controls have more properties stored than others?
3- Are all controls of the same type, or different types?? Do you know all the types you are declaring? Will there be UserControls, or controls unknown at design time involved?
Regards
|
|
|
|
|
The text file contains all the controls and it is of different types.. Some controls have more proerties stored and, yes I'm storing the location too..
Is there a command that executes this (the creation of controls?)?
Thank you!!
|
|
|
|
|
Well, one easy clumsy way -if you know all the types of controls you will declare- is to parse the text file and Create the controls in a switch. eg.
switch (MyInputType)
{
case "TextBox":
{
TextBox temp = new TextBox();
MyForm.Controls.Add(temp);
}
}
This way the temp variable will be destroyed, but the reference in the MyForms.Controls will keep the control alive. This way you can declare as many TextBoxes as you want.
If you expect UserControls or controls that you don't know its type, you'd have to use Reflection namespace which is by far bigger than to be covered in a single post.
PS.
Why use TextFile?? Why not XmlDocument?
Regards
|
|
|
|
|
I just started using C# in VS2003 (after learning vb.net)
When I type a variable name in VS2003 for a vb.net project - it corrects any capitalization for me.
Is there a way to do that for C# projects in VS2003 ?
Thanks.
|
|
|
|
|
Unlike VB, in C# variable names are case sensitive, so no. Otherwise how could you define a myVariable and a MyVariable? (not saying that that is a good idea mind).
|
|
|
|
|
Well thats my point - I dont want to so why not help me out a little on the capitalization ?
|
|
|
|
|
As it's case-sensitive it can't help you out in the way you want. However, in VS 2005 the IntelliSense is a bit more intelligent in the following way.
Suppose you write
int customer = 5;
Then you start typing CUs
Then IntelliSense will pop up and automatically select the customer declaration. If you tab then it will substitute customer for CUs.
But if you were to fully type CUstomer then it won't auto-correct it afterwards. In theory, though it could make an inference based on the fact that the only "CUstomer" that's been declared in scope is "customer."
Anyway, if you're in a position to try using C# 2005. It's a much nicer editing experience. As it happens, at work I'm using neither C# 2003 nor 2005 but VB 2003.
C# 2005's IntelliSense and code snippet behaviour is better than VB 2005's BTW.
Kevin
|
|
|
|
|
The development of an application that handles encryption (AES) of data stored in a database (SQL server 2005) at the application level through C#. So in practice I would in C# do some simple data handling and then encrypt these data and then insert these data in the corresponding DB tables. This is what I am trying to develop, but I am just in a researching face for the moment, hence my question.
Can anybody reply me on the how difficult this should be to accomplish and where to concentrate my researching and if any body as any form of input to this I am very pleased to receive this too.
Thank you
Kenn Kikkenborg
|
|
|
|
|
i use a class writen by Peter Huber, for pop3 client but i have a problem with it
I cannot establish a connection throw a proxy but when i use direct connection "not firewalled or proxy environment" its work good , are there any changes must done on this method ( connect() )???? or any help please:
public void Connect() {
if (pop3ConnectionState!=Pop3ConnectionStateEnum.Disconnected &&
pop3ConnectionState!=Pop3ConnectionStateEnum.Closed &&
!isTimeoutReconnect) {
CallWarning("connect", "", "Connect command received, but connection state is: " + pop3ConnectionState.ToString());
} else {
//establish TCP connection
try {
CallTrace(" Connect at port {0}", port);
serverTcpConnection = new TcpClient(popServer, port);
} catch (Exception ex) {
throw new Pop3Exception("Connection to server "+ popServer + ", port " + port + " failed.\nRuntime Error: "+ex.ToString());
}
if (useSSL) {
//get SSL stream
try {
CallTrace(" Get SSL connection");
pop3Stream = new SslStream(serverTcpConnection.GetStream(), false);
pop3Stream.ReadTimeout = readTimeout;
} catch (Exception ex) {
throw new Pop3Exception("Server " + popServer + " found, but cannot get SSL data stream.\nRuntime Error: "+ex.ToString());
}
//perform SSL authentication
try {
CallTrace(" Get SSL authentication");
((SslStream)pop3Stream).AuthenticateAsClient(popServer);
} catch (Exception ex) {
throw new Pop3Exception("Server " + popServer + " found, but problem with SSL Authentication.\nRuntime Error: " + ex.ToString());
}
} else {
//create a stream to POP3 server without using SSL
try {
CallTrace(" Get connection without SSL");
pop3Stream = serverTcpConnection.GetStream();
pop3Stream.ReadTimeout = readTimeout;
} catch (Exception ex) {
throw new Pop3Exception("Server " + popServer + " found, but cannot get data stream (without SSL).\nRuntime Error: "+ex.ToString());
}
}
//get stream for reading from pop server
//POP3 allows only US-ASCII. The message will be translated in the proper encoding in a later step
try {
pop3StreamReader= new StreamReader(pop3Stream, Encoding.ASCII);
} catch (Exception ex) {
if (useSSL) {
throw new Pop3Exception("Server " + popServer + " found, but cannot read from SSL stream.\nRuntime Error: " + ex.ToString());
} else {
throw new Pop3Exception("Server " + popServer + " found, but cannot read from stream (without SSL).\nRuntime Error: " + ex.ToString());
}
}
//ready for authorisation
string response;
if (!readSingleLine(out response)) {
throw new Pop3Exception("Server " + popServer + " not ready to start AUTHORIZATION.\nMessage: " + response);
}
setPop3ConnectionState(Pop3ConnectionStateEnum.Authorization);
//send user name
if (!executeCommand("USER "+ username, out response)) {
throw new Pop3Exception("Server " + popServer + " doesn't accept username '" + username + "'.\nMessage: " + response);
}
//send password
if (!executeCommand("PASS " + password, out response)) {
throw new Pop3Exception("Server " + popServer + " doesn't accept password '" + password + "' for user '" + username + "'.\nMessage: " + response);
}
setPop3ConnectionState(Pop3ConnectionStateEnum.Connected);
}
}
|
|
|
|
|
I want to display doc(MS Word) file. I have used rich text box control but it is not working. I want to show graphics (circles....) in my appliction. Is rich txt box is right choice or.... . Tell me about it. Please give me code example if possible.
Thanks
Syed Shahid Hussain
|
|
|
|
|
Hello Shahid.
You can't display Word Documents on your forms using RichTextBox, because it won't understand the formtting of the document.
First of all, check this article[^].
If it's not what you want, you'd have to use somthing called Word Interop -shorthand for Inter operability-
The namespace is Microsoft.Office.Interop.Word , but first you have to reference to it:
In the solution explorer =>Right click on your project's name => Add reference => COM tab => Microsoft Word object library
Important note:
This will require that MS Word is installed on your machine and the user's machine
and the office programming section[^] in the articles may be useful.
Best Regards
|
|
|
|