|
Never done this myself, but I think you can only avoid case sensitiveness by turning both the search string as well as the content of FirstName to either upper or lower case. For the search string you can use the appropriate methods provided by the String class. In case of the content of FirstName you'll have to use XPath functions[^].
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hi, can anyone please enlighten me on how to create dynamic objects with different names during run time?
Thanks =)
|
|
|
|
|
Unclear question but that might be the answer
Object obj = System.Activator.CreateInstance()
|
|
|
|
|
Hi
I'm showing a few tables (user selects which one he wants to edit using ComboBox).
The data is passed to DataGridView (variable dgvEditTable):
string strSQL = "select * from " + cbEditTable.SelectedItem.ToString();<br />
<br />
mySqlDataAdapter = new MySqlDataAdapter(strSQL, MySQLConnection.ConnectionString + ";allow zero datetime=yes");<br />
MySqlCommandBuilder commandBuilder = new MySqlCommandBuilder(mySqlDataAdapter);<br />
<br />
mySqlTableEdit = new DataTable();<br />
mySqlTableEdit.Locale = System.Globalization.CultureInfo.InvariantCulture;<br />
mySqlDataAdapter.Fill(mySqlTableEdit);<br />
<br />
BindingSource dbBindSource = new BindingSource();<br />
dbBindSource.DataSource = mySqlTableEdit;<br />
dgvEditTable.DataSource = dbBindSource;
I'm using MySql Connector .NET 1.0.9 as a provider.
Everything works great until the user don't touch a Date or DateTime field. When user puts some valid date [eg: 2006-05-20] and tries to leave edited cell DataGridView rises an exception:
The following exception occurred in the DataGridView:
System.FormatException: Invalid cast from 'System.String' to 'MySql.Data.Types.MySqlDateTime'. ---> System.InvalidCastException: Invalid cast from 'System.String' to 'MySql.Data.Types.MySqlDateTime'.
[... the rest of the stack of used methods ...]
I've found description of this exception here, but the only solution there is to change a type of field to String. Well, I've tried this but I got another exception "Cannot change DataType of a column once it has data.".
Any suggestions are welcome.
This is the one of the last parts of my final project for studies and I must finish it before end of May. I'm toasted
-- modified at 17:37 Thursday 17th May, 2007
-- modified at 17:39 Thursday 17th May, 2007
"In the brave new world of the year 2000, a kiss can still break your heart." - Program from Cirque du Soleil's Alegría
|
|
|
|
|
Hello,
I have this search method which is called when the user enter some value into textbox and presses Search button.
If a record is found, it's supposed to open a form called Account Management Form. What i wanted to achieve was, Close the search form right after the record is found and Acc Management Form is being opened.
this is the code i have so far:
private void doEditAccount(IAccount account)<br />
{<br />
this.close();<br />
AccountManageForm form = new AccountManageForm(account);<br />
form.ShowDialog();<br />
}<br />
<br />
private void searchBtn1_Click(object sender, EventArgs e)<br />
{<br />
string fileName = "Account_Data.xml";<br />
XPathDocument doc = new XPathDocument(fileName);<br />
XPathNavigator nav = doc.CreateNavigator();<br />
<br />
XPathExpression expr;<br />
expr = nav.Compile("//Account[@ID='" + accountIDInput.Text + "']");<br />
XPathNodeIterator iterator = nav.Select(expr);<br />
iterator = nav.Select(expr);<br />
<br />
if (iterator.MoveNext())<br />
{<br />
XPathNavigator nav2 = iterator.Current.Clone();<br />
string tmpAccID = (nav2.GetAttribute("ID", ""));<br />
nav2.MoveToFirstChild();<br />
string tmpName = (nav2.Value);<br />
<br />
IAccount account = new Account(tmpName, "");<br />
doEditAccount(account);<br />
}<br />
}
In theory, shouldn't the search form get closed because of the line this.close(); inside the doEditAccount method and then open the Acc Management Form...
but in my testing, the Adv Search Form won't close. Im i doing something wrong? or is there another way to force a form window to close before opening another one?
|
|
|
|
|
Latheesan wrote: this.close();
what is "this" ?
|
|
|
|
|
Correct me if im wrong, but isnt "this." used to select the current opened/active form?
Even if i don't use this.Close(); i tried the following options to form the form to close:
Close();
AdvSearchForm.ActiveForm.Close();
Still no luck, this is what i could think of top of my head and from my past exprience with form closing...
|
|
|
|
|
You obviously don't know C#, do you? The This keyword refers to the current instance of the class, kind of like the Me keyword in VB.
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
You obviously don't know C#, do you?
Yea you are correct, im still learning
|
|
|
|
|
May I suggest you buy a book on the C# language; and read, study and understand it
completely, so you know the language and some OO concepts, before you engage in creating fancy programs.
That too is "separation of concerns", one of the modern software concepts.
|
|
|
|
|
Latheesan wrote: Yea you are correct, im still learning
I was talking to Luc Pattyn . But if you need a good book on C#, I would suggest: Learning C# 2005.
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
MatrixCoder wrote: You obviously don't know C#, do you?
I'm guessing that Luc knows C# and was just requesting more info on the context of the code.
|
|
|
|
|
Did you try Application.Exit(); ?
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
Oh yea, i tried that too and it didn't work either.
Normally Close(); alone just works fine, but in this case, it's acting quite wierd...
|
|
|
|
|
Latheesan wrote: In theory, shouldn't the search form get closed because of the line this.close(); inside the doEditAccount method and then open the Acc Management Form...
No. The form.ShowDialog() code will block until the AccountManageForm is closed. Once that form is closed, the doEditAccount method will run to completion, control will be returned to the original form which will then process the close message.
|
|
|
|
|
Oh i get it. Is there any way to get around this?
|
|
|
|
|
Latheesan wrote: Is there any way to get around this?
Well, let's consider what you're trying to do. You have a main form in which the user can enter something they wish to search for into a text box. They hit a search button. If the item is found, a new form is opened for them to interact with.
What you want to do is close the original form with the text box and search button, correct?
The problem is that you want to close what is apparently the main form while keeping open a child form. I don't know of a way to do this. Why not instead use one main form and two child forms. One child form is for entering searches. Once the user has entered a search string and hit the search button, it's closed. The main form then opens the second child form, which uses the results of the search.
So you have a main form representing the basic functionality of the application and two child forms, one for searching, and the other for using the results of the search.
Make sense?
|
|
|
|
|
Yup, thanks allot for the info.
The need to close the Search Form before opening the Editing Form isn't exactly in the project requirement, it's a little feature i wanted to add, because 1) im a uber perfectionist and 2) it would have looked more professional and more user friendly (I felt as if i didnt have the search form close, it'll look messy with 3 form windows open from 1 software).
Thanks anyway =)
|
|
|
|
|
private void doEditAccount(IAccount account)
{
this.isVisible = false;
AccountManageForm form = new AccountManageForm(account);
form.ShowDialog();
}
Later, when the AccountManageForm is done running, you can make it visible again, or just not make it visble :P It's a bit of a hack, I guess, but you won't waste resources painting the form and get your desired functionality.
Hope it helps. I didn't test the code, but I'm 99% sure you can just hide the form and get what you want.
|
|
|
|
|
Hello,
I am trying to declare a series of buttons 9x9 using a dictionary type and if possible, have it show up in the VC# express form editor. I believe I am instantiating everything correctly. The problem is that the buttons never show up when I run the program.
//This is the form designer created by the VC# IDE.
//Form1.Designer.cs
namespace CS202_Final<br />
{<br />
partial class Quest202<br />
{<br />
private System.ComponentModel.IContainer components = null;<br />
<br />
<br />
protected override void Dispose(bool disposing)<br />
{<br />
if (disposing && (components != null))<br />
{<br />
components.Dispose();<br />
}<br />
base.Dispose(disposing);<br />
}<br />
<br />
<br />
<br />
#region Windows Form Designer generated code<br />
<br />
private void InitializeComponent()<br />
{<br />
this.menuStrip1 = new System.Windows.Forms.MenuStrip();<br />
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();<br />
this.newGameToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();<br />
this.button1 = new System.Windows.Forms.Button();<br />
this.menuStrip1.SuspendLayout();<br />
this.SuspendLayout();<br />
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {<br />
this.fileToolStripMenuItem});<br />
this.menuStrip1.Location = new System.Drawing.Point(0, 0);<br />
this.menuStrip1.Name = "menuStrip1";<br />
this.menuStrip1.Size = new System.Drawing.Size(929, 24);<br />
this.menuStrip1.TabIndex = 0;<br />
this.menuStrip1.Text = "menuStrip1";<br />
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {<br />
this.newGameToolStripMenuItem});<br />
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";<br />
this.fileToolStripMenuItem.Size = new System.Drawing.Size(35, 20);<br />
this.fileToolStripMenuItem.Text = "File";<br />
this.fileToolStripMenuItem.Click += new System.EventHandler(this.fileToolStripMenuItem_Click);<br />
this.newGameToolStripMenuItem.Name = "newGameToolStripMenuItem";<br />
this.newGameToolStripMenuItem.Size = new System.Drawing.Size(125, 22);<br />
this.newGameToolStripMenuItem.Text = "New Game";<br />
this.button1.BackColor = System.Drawing.Color.Transparent;<br />
this.button1.Location = new System.Drawing.Point(317, 96);<br />
this.button1.Name = "button1";<br />
this.button1.Size = new System.Drawing.Size(154, 129);<br />
this.button1.TabIndex = 1;<br />
this.button1.Text = "button1";<br />
this.button1.UseVisualStyleBackColor = false;<br />
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);<br />
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;<br />
this.ClientSize = new System.Drawing.Size(929, 711);<br />
this.Controls.Add(this.button1);<br />
this.Controls.Add(this.menuStrip1);<br />
this.MainMenuStrip = this.menuStrip1;<br />
this.Name = "Quest202";<br />
this.Text = "Quest 202";<br />
this.Load += new System.EventHandler(this.Quest202_Load);<br />
this.menuStrip1.ResumeLayout(false);<br />
this.menuStrip1.PerformLayout();<br />
this.ResumeLayout(false);<br />
this.PerformLayout();<br />
<br />
}<br />
<br />
#endregion<br />
<br />
private System.Windows.Forms.MenuStrip menuStrip1;<br />
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;<br />
private System.Windows.Forms.ToolStripMenuItem newGameToolStripMenuItem;<br />
private System.Collections.Generic.Dictionary<int, System.Windows.Forms.Button> button = new System.Collections.Generic.Dictionary<int, System.Windows.Forms.Button>();<br />
private System.Windows.Forms.Button button1;<br />
<br />
}<br />
}
The bold line is where I declare my dictionary type for holding buttons.
//This is where I actually instantiate the 81 buttons within the dictionary. I cannot get them to display for some reason.
//FORM1.CS
namespace CS202_Final<br />
{<br />
public partial class Quest202 : Form<br />
{<br />
public Quest202()<br />
{<br />
InitializeComponent();<br />
InitButtons();<br />
}<br />
<br />
public void InitButtons()<br />
{<br />
int counterx = 0;<br />
int countery = 0;<br />
string buttonname = "button";<br />
<br />
for (int i = 1; i <= 81; i++)<br />
{<br />
this.button.Add(i, new System.Windows.Forms.Button());<br />
this.button[i].Location = new System.Drawing.Point(173 + (counterx * 65), 61 + (countery * 66));<br />
this.button[i].Size = new System.Drawing.Size(63, 60);<br />
this.button[i].Name = buttonname.Insert(6, i.ToString());<br />
this.button[i].TabIndex = i;<br />
this.button[i].Text = buttonname.Insert(6, i.ToString());<br />
this.button[i].UseVisualStyleBackColor = true;<br />
this.button[i].Enabled = true;<br />
this.button[i].Visible = true;<br />
this.button[i].AccessibleRole = System.Windows.Forms.AccessibleRole.Default;<br />
this.button[i].BackgroundImageLayout = System.Windows.Forms.ImageLayout.Tile;<br />
this.button[i].BackColor = System.Drawing.Color.Gray;<br />
this.button[i].Cursor = System.Windows.Forms.Cursors.Default;<br />
<br />
<br />
countery++;<br />
if (i % 9 == 0)<br />
{<br />
counterx = counterx + 1;<br />
countery = 0;<br />
}<br />
}<br />
}
The bold section is where the real meat of the attempt lies. I have no idea what it takes to get those buttons to appear when I run the program. I am getting absolutely no complier errors or warnings. I have debuged the above sections and the compiler steps through them all. The program does not fail during runtime either. If someone could please help me out with this. That'd be great.
|
|
|
|
|
You need to add one line:
Controls.Add(button[i]);
at the end of your for loop. The Controls collection on a form contains all the controls that belong to the form. You have buttons, but they are not on the form.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Ah, Excellent. That's a great help.
BTW: This isn't my CS202 Final Project. I already Graduated from this University. The project was suppoed to be done in c++, but I needed practice in C# so I decided to look at my old university professors website and get some exercises. I don't really know a lot of places with good C# exercises.
Thanks again Christian.
|
|
|
|
|
Yeah, the Stroustrup C++ book came with excellent exercises, I don't know of a C# book that does the same.
No worries, glad to help.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hey, now i've hit another snag. Since i'm not all that familiar with C# (this is really my first big project in it) I was wondering how I handle events like clicks on these buttons.
I can't really create a fuction called
private void this.button[1]_Click(object sender, EventArgs e)
can i?
I don't think so.
How would I make it so that if i clicked on any of the 81 buttons, it would change the button.BackColor to System.Drawing.Color.Red?
User created event handlers is something i haven't learned or read about yet.
|
|
|
|
|
You can create a single click event, and the sender object identifies the button that sent it. So, if you set the Tag property of each button to identify the button, then you can do something like this:
Button btn = sender as Button;
if ( btn!=null)
{
switch(btn.Tag)
{
}
}
Not sure if switch will work or if you need a bunch of if then else statements. Tag may be an object.
Just read the rest of the question, sorry. As btn is now the button that you clicked, you can set any property, such as teh back color, and it will be set on the button that was clicked.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|