|
I could have sworn I tested exactly what you said and it didn't work (as indicated previous).
You provoked me in to setting up my test again and this time it did work. I must have overlooked something in my old test.
Thank you so much! I truly appreciate it!
|
|
|
|
|
|
Where are you defining the length of "count"? CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
I have a data application that is using a DataSet via the designer.
I'm trying to create a form that binds data from one table "MyData". One of the fields "picker_fk" uses an FK relationship to a second table "Picker". "Picker" has only one field in it called "descript" (not null, unique).
In the form, I set up the DataGridView to use the DataSet.MyData table. For the combo box column, I set the following properties:
DataPropertyName = "picker_fk"
DataSource = bndPicker (a binding source that uses the "Picker" table from the DataSet)
DisplayMember = "descript"
ValueMember = "descript"
This is all good until I create a new row, select a value from the combo box, and then move focus away. I get a message:
SystemArgumentException: Column "descript" is not belong to table "Picker".
What's up with that? I'm looking right at the field in the DataSetDesigner. "descript" is the ONE AND ONLY field in "Picker". How can the debugger say it's not in there?
I dug around and found a suggestion that this error could occur with data type mismatches. But I have verified that both Picker.descript and the referencing MyData.picker_fk are both of type System.String.
Does anyone have any ideas?
|
|
|
|
|
Never mind. I found it. The error message is actually misleading because it doesn't have to do with the names. It has to do with the sequence in which databinding takes place. I set up the BindingSource for the grid BEFORE the BindingSource for the ComboBox options. It's odd that this error was not detected right away but only after adding a row, but I'm not the only one to experience this:
http://adamhouldsworth.blogspot.com/2009_04_01_archive.html[^] (Scroll down to the 7 April 2009 entry "Data Binding Pitfall").
|
|
|
|
|
What is the format needed for Intellisense to pick up on my comments for my enums? So when I type “MyEnum.ItemOne” the intellisense will display the documentation I’ve written for “ItemOne”?
Also, is there some sort of command I can use in Visual Studio that will generate a compile error if I don’t use all possible Enum values in a switch statement? I’m looking for a compile-time dummy catch incase I add an extra Enum value later but might miss a statement that should switch on all possible values of the Enum.
Thanks!
|
|
|
|
|
public enum Blah
{
Terror,
Nitro
}
[Edit]Fixed "<" signs
For Point 2: Not that I know of.
But It shouldn't be too hard to create a method that checks each enumeration used.
[/Edit]
|
|
|
|
|
Thanks, works perfectly! I was trying variations on
public enum MyEnum
{
ItemOne
}
with no success =/
|
|
|
|
|
what the System.Terror?
It sure does. If you mess with it you're f... modified on Friday, March 5, 2010 6:33 PM
|
|
|
|
|
Anticast wrote: a compile error if I don’t use all possible Enum values
nope.
you could come up with extra code that performs some checks, but it isn't straightforward.
|
|
|
|
|
If you use "tab tab" for the switch it will automatically put in all cases
|
|
|
|
|
that's a good one. i had no ideea. thanks![Thumbs Up | :thumbsup:](https://codeproject.freetls.fastly.net/script/Forums/Images/thumbs_up.gif)
|
|
|
|
|
I didn't know this until recently, when I did it by accident - imagine the chances of that happening ! ![Smile | :)](https://codeproject.freetls.fastly.net/script/Forums/Images/smiley_smile.gif)
|
|
|
|
|
cool ![Big Grin | :-D](https://codeproject.freetls.fastly.net/script/Forums/Images/smiley_biggrin.gif)
|
|
|
|
|
I agree, thanks for the tip!
|
|
|
|
|
I had no idea! Real cool! -Bryan
My latest programming adventure was coding the multimedia features for the Rip Ride Rockit coaster at Universal Studios Florida. I love my job.
|
|
|
|
|
You may want to check out GhostDoc[^]
It is a free add on for Visual Studio that makes documenting stuff (for Intellisense or not) realy easy.
Ctl+Shift+d while the insertion point is in your enum and all of the ///<summary></summary> tags for each option are inserted (and the stuff at the top).
I am a bit of a fan since I found it.
|
|
|
|
|
Putting all enums in a switch statement simply because they exist is pointless. There are MANY times when you simply don't care about 1 or more of the ordinals (lumping their handling into the default: clause)..45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hi,
i am trying to write a title to an image and save it back to its current location but i am having a problem as the following message is being thrown:
A generic error occured in GDI+
A first chance exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll
System.Drawing
A first chance exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll
System.Drawing
Error code: -2147467259
" at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)\r\n
at System.Drawing.Image.Save(String filename, ImageFormat format)\r\n at ZooSystem.ImageViewer.ApplyChanges()
in E:\\ZooSystem\\\ImageViewer.cs:line 520"
I have checked the permissions for each of the images in the folder and they all have FullControl/Read/Write/Modify permissions but the folder has "Read-Only" enabled.
The folder was created on the Internal Hard drive of the computer and I am using Windows Vista Home Premium 32-bit. I am using MS VS 2008 Pro edition which i run in Admin mode.
If i save the images to another folder say one of the Public folders then the above exception is not thrown.
But I would like to save my images to the same folder if possible?
How could i go about doing this? I would appreciate if somebody could help me with the above. I have been trying to fix it for past 2 hours.
Thanks,
Here is the code i am using:
private void ApplyChanges()
{
if(txtBoxOut.Text.Equals("")
{
if(sfd.ShowDialog()==DialogResult.OK)
{
this.SaveTheImage(sfd.FileName,this.bmp);
}
}
else if(txtBoxOut.Text != "")
{
string destFolder = txtBoxOut.text
foreach(string filePath in filePaths)
{
this.bmp = Image.FromFile(filePath);
string fileName = Path.GetFileName(filePath);
try
{
if(destFolder.EndsWith("\\")
{
this.bmp.Save(destFolder+fileName+ImageFormat.Jpeg);
}
else
{
this.bmp.Save(destFolder+"\\"+fileName+ImageFormat.Jpeg);
}
}
catch(Exception e)
{
Console.WriteLine(e.message.ToString());
}
}
}
}
|
|
|
|
|
Most, if not all, errors inside GDI+ are reported as "generic problem occurred in GDI+". If the affected line is an Image.Save chances are your path is incorrect or inaccessible, your disk is full, or your destination file exists and is locked.
If you load an image from a file, most of the time the file remains locked as long as the Image is alive. This would prevent you from saving an image to the same path.
It applies to Image.FromFile, and probably also to PictureBox.ImageLocation
The one exception I am aware of is when you use Image.FromStream.
So I suggest one of these two workarounds:
Bitmap bm=null;
{
Bitmap bm1=Image.FromFile(filepath);
bm=new Bitmap(bm1);
bm1.Dispose();
}
or
Bitmap bm=null;
using (FileStream stream=File.OpenRead("image.jpeg")) {
bm=Image.FromStream(stream);
}
|
|
|
|
|
According to Documentation[^]
"You must keep the stream open for the lifetime of the Image." so should not the second snippet throw an exception?
|
|
|
|
|
Hi Giorgi,
Thanks. I missed that line in the documentation, and no it has never thrown me an Exception; AFAIK once the pixels are loaded, file (and now also the stream) access is needed only when extra information is asked for, (e.g.the JPEG tags), which I don't ask for unless I use Image.FromFile().
Theoretically I now must change my standard reply to always create a copy of the first image, then dispose of it. Grr.
|
|
|
|
|
Windows probably has the bitmap locked if you are saving the file over itself.
If you are trying to save the image over itself. First, create a copy of the image and dispose of the original bitmap. Then apply the title to the copy and save it over the original image. Once disposed, it should not give you any problems.
you can use the Bitmap(Bitmap) constructor in order to make a copy.-Bryan
My latest programming adventure was coding the multimedia features for the Rip Ride Rockit coaster at Universal Studios Florida. I love my job.
|
|
|
|
|
Hi,
Thanks for the advice.
I have checked the amount of space on my HDD and i have 255 GB free. I am trying to save the images back to a folder which is located in "Pictures" folder.
I tried to make a copy of the image but it still throws an exception. My write method writes the title to the global image after i have created the image.
I am using Filestream as advised. I have wrapped the whole block of code when using the "using" directive.
I also dispose the global image after i have made a copy of it. I used the clone method and then use the cloned image to be saved. But i still get the same error message.
Any thoughts?
Here is a segment of the code:
else if(txtBoxOut.Text != "")
{
string destFolder = txtBoxOut.text
foreach(string filePath in filePaths)
{
using(FileStream fileStream = File.OpenRead(filePath))
{
this.bmp = Image.FromStream(fileStream);
string fileName = Path.GetFileName(filePath);
try
{
Image newImage = (Image)this.bmp.Clone();
this.bmp.Dispose();
if(destFolder.EndsWith("\\")
{
this.newImage.Save(destFolder+fileName+ImageFormat.Jpeg);
}
else
{
this.newImage.Save(destFolder+"\\"+fileName+ImageFormat.Jpeg);
}
}
catch(Exception e)
{
Console.WriteLine(e.message.ToString());
}
}
}
}
|
|
|
|
|
Hi,
In this bit of code you still have the stream open because you are doing your bitmap operations inside your using. Windows may still have hold of the bitmap. Copy the bitmap inside the using and do the other stuff outside of the using. See if that works. something like this...
using(FileStream fileStream = File.OpenRead(filePath))
{
this.bmp = Image.FromStream(fileStream);
string fileName = Path.GetFileName(filePath);
Image newImage = (Image)this.bmp.Clone();
this.bmp.Dispose();
}
if(destFolder.EndsWith("\\"))
.
.
. -Bryan
My latest programming adventure was coding the multimedia features for the Rip Ride Rockit coaster at Universal Studios Florida. I love my job.
|
|
|
|