|
You are, of course, right. I will need to somehow push this task into a background thread.
Thanks,
Keith
|
|
|
|
|
you're welcome.
|
|
|
|
|
Hello,
I have a combo box that is bound to a dictionary item.
dictonary"<"Guid, string">" m_test = new dictonary"<"Guid, string">"();
then on my windows form I have a combo box cboUser
cboUser.DisplayMember = "Value";
cboUser.ValueMember = "Key";
cboUser.DataSource = new BindingSource(m_test, null);
In m_test I do not have any blank entries and if possible I would like to keep blanks out.
The combo boxes are filling in as expected. But it is filling in the text with the first entry. This is causing the modified flag to be set to true. If it were blank the flag would not get set so if the user tries to close and no changes were made then it would close without prompting for save.
Thanks
|
|
|
|
|
It really depends which technology you are using, i.e. is it WinForms or Web Forms. You should be able to insert a new item into the cboUser.Items collection at position 0 which does what you want.
|
|
|
|
|
It is a winforms app.
Tried your idea but the issue when you have a data source set it comes back with an error. Cannot modify collection while datasource property is set....
Tried inserting the item prior to setting the datasource but still same issue.
|
|
|
|
|
OK - as it's WinForms, you need to update the dictionary just before you bind it in. Just add m_test.Insert(Guid.NewGuid(), " "); before you bind the items in.
|
|
|
|
|
I'm trying to use reflection to generate a report from my classes. The trouble comes with class fields that are lists of other, smaller, classes that will be reported as tables. I can isolate those fields using properties ([ReportAttribute("GenerateTable")] )in my class definitions, and get the next layer down with:
foreach (FieldInfo fi in FieldsThatAreLists)
{
IList list = (IList)fi.GetValue(this);
if (list[0] is MyClass)
{
List<MyClass> templist = ((List<MyClass>)list).OrderBy(mc=>mc.Index).ToList();
list = (IList)newlist;
}
else if (repeat for every possible class...)
ReportGenerate(list);
}
Since all of my (smaller) classes have a property called "Index", is it possible to eliminate the maintenance crushing if (list[0] is MyClass) ... with something more elegant?
And once that's done, the ReportGenerate() method needs to sort the order of things in each class to get the report columns straight. I'm working on doing this with more properties in each class definition, but is there a simpler way?
|
|
|
|
|
Make all of your smaller classes implement a common interface:
public interface IIndexedList
{
int Index { get; }
}
That way, you can just test for IIndexedList, and cast to that.
As for your next question... You can sort by anything, not just a single property. When you specify mc=>mc.Index , you're defining a function that takes mc as an argument and returns mc.Index. You could return anything you want, as long as OrderBy can sort it... Number, string, date, etc.
|
|
|
|
|
Thanks, Ian. I'll take a look at interfaces.
My second question is about controlling the order of class properties returned when reflecting. I need to see the fields themselves to set up columns into which the values will eventually be placed. I can make it work by adding a property declaration for each field, but I was wondering if there's something else available with reflection to control the order in which fields are returned.
It seems to depend on inheritance order followed by position within the class declaration, but I can't find it documented so I don't want to depend on it, and in any event, the inheritance ordering messes it up for my case.
|
|
|
|
|
As far as I know, you can't control what order they come back in, so either you sort it yourself based on name or type, or you tag them with attributes.
|
|
|
|
|
I think I've got the interface working, and the test works:
if(list[0] is IIndexedListItem) .
I'm getting an InvalidCastException when I try to cast the list:
List<IIndexedListItem> newlist = (List<IIndexedListItem>)list;
Instead, I tried:
List<IIndexedListItem> newlist = new List<IIndexedListItem>();
foreach(IIndexedListItem item in list)
{
newlist.Add(item);
}
newlist = newlist.OrderBy(p => p.Index).ToList();
This does what I need, so I'm back to work, I just wonder if I'm missing something easy about casting the lists.
|
|
|
|
|
Try list.Cast<IIndexedListItem>()
|
|
|
|
|
If you don't want to use all that fancy LINQ stuff, you can use List.ConvertAll to convert from a list of one type to a list of another type:
List<Animal> myAnimals = (new List<Dog> { new Dog() }).ConvertAll<Animal>(delegate(Dog d) { return d; });
|
|
|
|
|
Hello all
I want to write an application for a Windows CE or Pocket PC device that will print to a printer. I.e. My application will be on a handheld device and i will connect my handheld device to the printer by USB cable, when the user clicks print it will print the printer that the user has set up on that handheld device. wondering if someone could point me in the right direction for information on how to do this. I just want to print text in different fonts. Is this possible in C#?
Thank you
|
|
|
|
|
I have never tried it, don't know if it works, etc., but you might look Smart Device Print Engine for Compact Framework[^]
I don't know how well it will all work - you may need to talk to the physical printer in it's own langauge as I've never seen a printer driver specifically for Windows CE/Mobile.
Let us know if it works, I'd be very interested...
[edit]Don't post the same question in multiple places: It duplicates work and annoys people. If I had known you had posted in here and in Q&A then I would probably have replied there. I have deleted your Q&A question.[/edit]
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Hi All,
I am new in this .and i have to create a application in which a virtual Directory in IIS and aal the details from sql server will be fatched and shoing in our application.anybody can guide me how i can create it.....I'll wait for reply...
regards:
Gourav
+91-9871157845
|
|
|
|
|
Here it is.[^]
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
|
|
|
|
|
In my application I have a picturebox control which displays a bitmap I have created from a byte array. This works quite well most of the time, however if I resize the form the image will sometimes get corrupt. Sometimes it even draws other bitmaps that are being used by completely different forms.
This[^] is what the picturebox looks like when it's doing what it's supposed to.
Random corruption[^] Note that this isn't actually random at all. Whenever I get a pattern similar to this, it's the exact same pattern.
More corruption[^]
I haven't overridden the paint event for the picturebox or anything fancy like that. The only owner-drawn control in the form is the rainbow colour bar you can see on the right.
I've googled this to death and haven't been able to come up with anything, I'm really lost here. Help is well-appreciated.
|
|
|
|
|
How did you create the bitmap from the byte array?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
private Bitmap createBitmap(uint width, uint height, byte[] pixels)
{
if (width == 0)
{
throw new ArgumentException("Bitmap width must be greater than 0.");
}
if (height == 0)
{
throw new ArgumentException("Bitmap height must be greater than 0.");
}
UInt32 byteCount = width * height * 4;
System.IntPtr pPixels = System.Runtime.InteropServices.Marshal.AllocHGlobal((int)(byteCount));
System.Runtime.InteropServices.Marshal.Copy(pixels, 0, pPixels, pixels.Length);
Bitmap bmp = new Bitmap((int)width, (int)height, (int)width * 4, System.Drawing.Imaging.PixelFormat.Format32bppArgb, pPixels);
System.Runtime.InteropServices.Marshal.FreeHGlobal(pPixels);
return bmp;
}
|
|
|
|
|
Hi,
the corruption you are seeing is typical when there is a mismatc in the image width, i.e. when scanlines are wider/narrower than the metadata indicates.
There are many ways to create a bitmap; any way that creates them from raw data requires the data to remain available as long as the image lives (i.e. isn't garbage collected), e.g.:
1. Image.FromFile() locks the file, as it may need to read the file again;
2. Image.FromStream() reqeusts the stream remains available and intact (although it often doesn't matter);
3. new Bitmap(..., rawDataPointer,...) requires the raw data to be available permanently.
1. enforces the file presence by locking the file (of course you could still get disconnected from the drive); 2 and 3 can't enforce anything, and are the likely cause for your image corruption.
BTW: all the above is in the fine manual, so RTFM.
|
|
|
|
|
Thanks for the info, that will be very helpful..
I guess C# has spoiled me... it has much better intellisense support than C++ - as a result I haven't found myself needing to read any of the documentation on msdn
|
|
|
|
|
You're welcome.
Whatever intellistuff they add, as long as MSDN holds more, one should read it. The remarks section is quite valuable most of the time.
|
|
|
|
|
Hi i am new in c#.
I am developing an application which have a main form(frmstart) and second form (frmreader).
i am moving from frmstart to frmReader form by a button click.
it work fine.
before moving to frmReader i hide frmStart. now i am on frmReader and i want to return back to my previous frmStart form. which is hidden. please tell me how to unhide the form.
# code MovetoFrmReader
frmReader R1 = new frmReader();
this.Hide();
R1.Show();
#code Returmback to frmStart
this.Dispose();
???
here in place of ??? what i need to write.
Please Help me.
Thanks
Ravindra
|
|
|
|
|
Firstly, don't use Dispose, use Close instead - it will be disposed later when the CG gets round to it. Remember that your form may have results that the main form expects to be able to pick up.
Instead, either
1) Pass the frmStart instance to frmReader (not brilliant, but it will work) and use the Show method on it before you Close() frmReader. This may give you problems if you miss a way to close teh form that you are not handling.
or
2) Use R1.ShowDialog(); instead of R1.Show(); This will prevent frmStart from proceeding until frmReader is closed. It can then unhide itself. (Much preferable, as frmReader can be more generic and does not need to know about the existance of frmStart)
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|