|
|
Hi Saksida:
.net 2.0 SP2 is already installed so the problem is something else.
Chuck
|
|
|
|
|
string str2= "";
foreach ( str2 in this.String_Array)
{
if (str2 != "")
{
flag2 = true;
break;
}
}
Error is
Cannot assign to 'str' because it is a 'foreach iteration variable'
Error
Type and identifier are both required in a foreach statement
If you can think then I Can.
|
|
|
|
|
A foreach iteration variable should be declared IN the foreach statement itself. You cannot reuse a previously declared variable, as in the case of 'for' loop.
This should work:
foreach (String str2 in this.String_Array)
Delete the first line that declares str2.
|
|
|
|
|
But the Error Getting Similer. I already use it.
If you can think then I Can.
|
|
|
|
|
Please be more descriptive. Post your code and the error message.
|
|
|
|
|
As Shamel said it, you need to have it like this:
foreach ( String str2 in this.String_Array)
{
if (str2 != "")
{
flag2 = true;
break;
}
}
eg_Anubhava wrote: Cannot assign to 'str' because it is a 'foreach iteration variable'
I frequently got this error, when I tried to change str2 and this.String_Array inside ForEach loop. My workaround was to create temp List, then I changed String_Array outside foreach loop
|
|
|
|
|
thank you sir my meaning is same
If you can think then I Can.
|
|
|
|
|
I Did create empty windows Form, and I Put your sample, and it worked without any error.
Have you posted your actual code? If Not, please post actual foreach loop.
Where and How do you use and initialize String_Array and Flag?
What Exception do you get and at witch line?
|
|
|
|
|
i have found the solution for that:
the solution is : The language does not allow you to reassign a "foreach" variable. Even
if you could, it wouldn't update the contents of hte array. What do
you want to do here? If you want to change the values in the array,
then you will have to do somehing like.
for(int i = 0 ; i < arrfile.Length; i++)
{
str = arrfile[i]
}
If you can think then I Can.
|
|
|
|
|
hi there,
i am trying to bind a textBox with a MS-SQL table fiels in this way:
dataAdapter.Fill(dataSet, tableName);
textBox.DataBindings.Add("Text", dataSet.Tables[tableName], "someField");
the thing is, that while using dataAdapter.Fill() method, the textBox is really filled...BUT when i am making changes in the textBox the modification doesn't reflect in the DB.
what am i missing in order to make this bind 2-way???
thx!
|
|
|
|
|
You're probably not using WPF. I've never heard of text boxes magically doing this, and if they did, I still wouldn't touch it with a barge pole.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Until you've issued a dataAdapter.Update(), changes won't be "reflected in the DB".
"Data binding" deals with controls and sources of data "in memory" (in your case, the DataSet; in other cases, it might be a different type of object, such as an Entity Model query). To get the data from the "in memory" data source to the "data store" (i.e. the "Database") one needs to issue an Update() sometime; the type of Update being dependent on the data source.
|
|
|
|
|
i used this data adapter instance later on when the user clicks on some button.
the INSERT,SELECT,UPDATE,DELETE commands were set.
then :
dataAdapter.Fill(dataSet, tableName);
textBox.DataBindings.Add("Text", dataSet.Tables[tableName], "someField");
and then later on:
da.Update(dataSet, tableName)
doesn't work...
i read somewhere that this binding is not Bi-Directional.
never mind.. thx guys anyway.
eventually i used the SqlDataReader. simple, easy, and... works!
|
|
|
|
|
hi to all, i was wondering if i can get some help,
i'm srawing on tabs of tab control item that has string and a-16X16 pixel icon of cancel button,
(just like the tabs in a regular browser that have a small button to close the tab).
anyway, i'm tring to make the icon on the selected tab to be red and the other tabs gray.
here is the code:
private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
Image img1 = new Bitmap(Application.StartupPath + "\\icons\\cancelGray.png");
Image img2 = new Bitmap(Application.StartupPath + "\\icons\\cancelRed.png");
Rectangle r = e.Bounds;
r = this.tabControl1.GetTabRect(e.Index);
r.Offset(2, 4);
Brush TitleBrush = new SolidBrush(Color.Black);
Font f = new Font("Microsoft Sans Serif", 8.0f);
string title = this.tabControl1.TabPages[e.Index].Text;
e.Graphics.DrawString(title, f, TitleBrush, new PointF(r.X, r.Y));
foreach (TabPage tp in tabControl1.TabPages)
{
if (tp == lastSelected) //LAST SELECTED IS THE THE CURRENT TABPAGE THAT SELECTED.
e.Graphics.DrawImage(img2, new Point(r.X + (this.tabControl1.GetTabRect(e.Index).Width - _imageLocation.X) - 7, _imageLocation.Y));
else e.Graphics.DrawImage(img1, new Point(r.X + (this.tabControl1.GetTabRect(e.Index).Width - _imageLocation.X) - 7, _imageLocation.Y));
}
}
the problem is that the changing colors of the tabs is not correct, i can't figure why when i'm clicking one tab the other is change..
thanks,
modified 31-Dec-20 21:02pm.
|
|
|
|
|
Hi,
in general events may fire more often than you would expect, so it is unwise to use status information from elsewhere when this can be avoided, as such data might be incorrect.
More in particular: why are you using your lastSelected when you have TabControl.TabPages[TabControl.SelectedTab] which is bound to always be the correct current page?
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
what do you suggest instead of the foreach?
and i tried the tabControl1.SelectedTab instead of the lastSelected before, it's only a bad try to fix the problem.
modified 31-Dec-20 21:02pm.
|
|
|
|
|
sagiko wrote: what do you suggest instead of the foreach?
Nothing.
I can't help you any further lacking precise scenarios and symptoms.
sagiko wrote: it's only a bad try to fix the problem
that does not help at all.
To be as vague as you are: fix the problem.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
modified 31-Dec-20 21:02pm.
|
|
|
|
|
Hi all.
I am trying to delete a directory and using
Directory.Delete("some_file_path");
These works just fine if the directory has no files in it but if it has any file, it does not get deleted. What should i do to delete a directory with or without a file?
Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
|
|
|
|
|
Hi,
write code to delete any files in the directory tree you want to delete. There are basically two ways:
1. ask a list of all files with a GetFiles(path, "*", SearchOptions.AllDirectories), delete all of them, then delete all (now empty) folders and subfolders using Directory.Delete(path, true);
2. write a depth-first recursive method that locates files, deletes them, then deletes the subfolder; this is slightly harder but doesn't get the big memory penalty on huge folders.
NB: since .NET 4.0 there are new methods that relieve the memory consumptions in (1)
PS: there is bound to be a native method that does it all; calling it would require some P/Invoke.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Luc Pattyn wrote: there is bound to be a native method that does it all;
I looked, and was surprised to find that there wasn't one in the Win2K native API. Even then it was still necessary to empty a directory before removing it. I haven't looked at this book (Windows NT/2000 Native API Reference) in a decade, and found it amusing to see ZwCreateMutant and ZwReleaseMutant. I wonder if that was part of Bill's plan to take over the world? It would explain a lot of things about Congress in recent years...
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
I think this will do it.
DirectoryInfo d;
d.Delete(true);
|
|
|
|
|
Which directory will this code delete ?
|
|
|
|
|
There is an overloaded Delete method that takes a boolean parameter 'recursive' to specify that you want the delete operation to be recursive, that is, to delete all subdirectories, files, etc. in the specified path.
This code will do the trick.
Directory.Delete("some_file_path", true);
|
|
|
|