|
Yes, but I don't have any code where I populate the lists, where I can inject another entry. If I did, I would have, but as it stands, simply setting SelectedIndex to -1 seems less complicated for extra code than inserting a list item.
|
|
|
|
|
This is a known bug in the WinForms combobox. Try setting SelectedIndex = -1 twice (don't ask...)
It has become appallingly obvious that our technology has exceeded our humanity. - Albert Einstein
|
|
|
|
|
Hi all,
pls help me
in my application using C#.net (window form) i need to save a .txt file. but if the same filename exist i need to save it as a new filename.
i have searched in net but could only find deleting existing or overwritting on the file.
pls help to get some solution
|
|
|
|
|
u can use GUID(Global Unique Identifier) for saving the text file with unique name
|
|
|
|
|
One very simple approach I take is simply create a while-loop that increments an integer, appends it to the filename (without the extension, of course), and checks for existence (after re-appending the extension). So long as that filename exists, I increment the variable again and try the next number.
Remember to include a failsafe in case the loop accidentally runs forever. Limit it to 10 or 100 iterations for example. I suppose a for-loop would be more convenient in this case then, but a while loop is more syntactically meaningful.
It has become appallingly obvious that our technology has exceeded our humanity. - Albert Einstein
|
|
|
|
|
One of the System.IO classes, I think it is Path, has a method that returns a unique file name.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi
I have a main form which opens a thread that opens a new form.
in the new form i'm trying to open an OpenFileDialog.
when i'm trying:
"if (projectFormOpenFileDialog.ShowDialog() == DialogResult.OK)"
when running at debug mode i'm getting:
"Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process..."
i have declared [STAThread] in the mainform function that opens the new form, also on the event that invokes the openfiledialog function.
help on this will be most appreciated
thanks,
Yohay
|
|
|
|
|
OpenFileDialog cannot be shown from any thread other than your main GUI thread. You cannot open it from a background thread. You'll need to change your program accordingly (and by the way, you shouldn't be showing other forms from background threads, either).
It has become appallingly obvious that our technology has exceeded our humanity. - Albert Einstein
|
|
|
|
|
many thanks for your help.
y
|
|
|
|
|
I have a parent child relationship, on DocumentID, between an invoice and invoice lines. A form displays invoice fields and has a grid for invoice lines. The grids BindingSource points to the Invoice Binding Source, and it's DataMember to the relation, so I think this is correct.
Now, if I leave the relation type to Only Relation, the DocumentID in my new Invoice is -1, and the DocumentID in my Invoice Lines grid is also -1, but the Line record remains -1 after being written to the database. So, I think maybe I should make the relation a constrain as well and add a cascade update, but then I get an error that -1 doesn't exist in the parent table, even though the Invoice datatable DocumentID is -1.
|
|
|
|
|
With an XmlDataDocument (based on a DataSet and an XmlDocument) and a BindingSource, I've found that I have to add a handler to AddRow for the child and wire up the child's FK to the parent manually. Don't know if that helps in your case.
However, obviously (or it should be obvious) the invoice DocumentID has to exist. If you're using identities, you'll have to save the invoice row first, get the DocumentID, put it into the invoice line FK's, and save the invoice lines.
Marc
|
|
|
|
|
Hi Mark, thanks for the advice, but as I have it, establishing a DataRelation between the two tables should be enough for ADO.NET to know to cascade the new parent primary key value to the new child records.
In fact, it is enough, but I have to call EndEdit after calling AddNew on my parent binding source. This makes the -1 PK availble to child FK, and the relation is established. Now when use the table adapters to update my DocumentTable and then DocumentLine table, the automatic cascade of the PK to the FK works perfectly.
|
|
|
|
|
Brady Kelly wrote: but I have to call EndEdit
So that was what was missing?
Brady Kelly wrote: Now when use the table adapters to update my DocumentTable and then DocumentLine table, the automatic cascade of the PK to the FK works perfectly.
Huh. That's pretty impressive. I've never actually seen that behavior--I'll have to revisit some code I recently finished where I had manually assign the FK. It'd be useful to reduce this whole issue into a small, simple, test case.
Marc
|
|
|
|
|
What is the best way to do this? Implement the content forms as controls, and factor the commonalities out into a host form, or to inherit from a base form. Somehow I think the latter is not as simple as it sounds, but I haven't tried either yet, I'm just checking.
|
|
|
|
|
Hi Brady,
if you need a number of forms all sharing some characteristics or capabilities, it seems
logical to me to define such a specialized form class, then instantiate it (or one of
its derivatives). That is OO for you.
If on the other hand, the commonality is not in the form itself, but rather in the
objects (Controls) it contains, creating one or more UserControls may be the way to go;
in this case, the form isn't anything special, you mainly make it easier to populate it.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Well, the forms all share a common layout, toolbar, and menus, so my consdered options are to write a base form with those, inherit, and override some methods use by those, or to write a host form like that for content controls, and expose a generic interface on the controls to react to the interface of the host form.
|
|
|
|
|
Seems it is all about overall aspects such as look-and-feel, and not specific content.
So I would go with the specialized form and derive more forms from it.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
hello
i m having a timer event which runs on after 1 minute
in my project i m having the appointment details...so it throws a message that u r having appointment on this time with this person before a particular time(depends on user)..so for this i use a timer event like...
void myTimer_Elapsed(object sender, ElapsedEventArgs e)
{
strCon = strCon.Replace("CONNECTIONSTRING", "Data Source='D:\\Neetu\\Training\\My_Diary_Database.mdb';Provider='Microsoft.Jet.OLEDB.4.0';Jet OLEDB:Database Password='neetu';");
con = new OleDbConnection(strCon);
query = "select alertSetting from settings where ID1=1 ";
cmd = new OleDbCommand(query, con);
con.Open();
dr = cmd.ExecuteReader();
if (dr.Read())
{
setting = Convert.ToInt32(dr["alertSetting"]);
}
con.Close();
dt1 = System.DateTime.Today.AddDays(3);
dt = System.DateTime.Now.AddMinutes(setting);
appointment_reminder(dt, dt1);
}
private void appointment_reminder(DateTime addTime, DateTime Time)
{
int i=0,check = 0;
string appointQuery;
DateTime newdt = addTime, newdt1 = Time;
con = new OleDbConnection(strCon);
DateTime dt = System.DateTime.Now;
string dtToday1 = newdt.ToString("MM/dd/yyyy hh:mm:00 tt");
string dtToday = dt.ToString("MM/dd/yyyy");
appointQuery = @"SELECT * FROM appointment WHERE Apntmnt_date=CDate('" + dtToday + "') and Apntmnt_time = CDate('" + Convert.ToDateTime(dtToday1) + "') order by Apntmnt_time";
cmd = new OleDbCommand(appointQuery, con);
con.Open();
if (con.State.ToString() == "Open")
{
dr = cmd.ExecuteReader();
while (dr.Read())
{
check = 1;
string myTime = dr["Apntmnt_time"].ToString();
strName = dr["Apntmnt_Person"].ToString();
strplace = dr["Apntmnt_Place"].ToString();
i++;
DateTime currentTime1 = Convert.ToDateTime(myTime);
string strTime1 = currentTime1.ToString("hh:mm");
DateTime currentTime = System.DateTime.Now.AddMinutes(setting);
string strTime = currentTime.ToString("hh:mm");
MessageBox.Show("Hello! You Are Having Appointment With " + strName + " At " + strplace + " On Time " + currentTime1);
}
con.Close();
}
}
my problem is this i want to know..m i doing right coz sometimes it gives the error that database connection state is connecting...n some thread problem....so help me...how shud i use this timer event..
|
|
|
|
|
Your errors relate to your ad hoc use of database code, not the use of a timer. Try telling is the exact error messages and what lines create them if you want more specific help.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Try Closing the Datareader
dr.Close();
Develop2Program & Program2Develop
|
|
|
|
|
AOA Dears!
When I parse TextBox1.text into int or Int32 The exception accurs
"Input String is not in correct formate"
How can i resolve this Problem.
Thanks
|
|
|
|
|
Sohail Ahmad wrote: When I parse TextBox1.text into int or Int32 The exception accurs
"Input String is not in correct formate"
How can i resolve this Problem.
Don't type stuff in the text box that isn't an integer.
Seriously, if you expect that the input may not be in the correct format use TryParse instead as it will return a boolean value to indicate if the string could be parsed or not.
Alternatively, catch the exception and handle it. (That much should not have been hard to figure out. Should it?)
|
|
|
|
|
one of the things most Parse() methods don't like is an empty string.
maybe your app is somehow executing your parse code before the box got filled?
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I want to get no of Rectengle from user:
Private void Button1_Click(Object sender, MouserEventsArg e)
{
int No_Rect;
No_Rect=int.Parse(Textbox1.text);
for(int i=0;i<no_rect;i++)>
{
e.Graphics.DrawRectanle(............);
}
}
In this Situation
"Input String is not in coorect Format"
Exception Rais. is any other way of parse string to int?
|
|
|
|
|
Hi,
I recommend you try and understand what goes wrong, rather than look for another approach.
There is nothing wrong with the approach, so it must be in the details.
First and forall, look at the symptoms and describe them in full detail when asking this
kind of questions.
Did you check the content of Textbox1.Text? Add some code right where you need it,
and show the value to yourself. Do not assume everything is all-right, since it
clearly is not, otherwise you would not ask for help.
is it a valid number (no more no less)? is it empty? does it contain non-digits?
why don't you use a try-catch block and show the exception.ToString()?
that should tell a lot.
BTW: you should not draw things in a button click handler, anyway e.Graphics will not
be available there.
Seems to me you are a novice in C#, and could benefit a lot from buying and reading
in introductory book on C#.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|