|
I have a form which contains a tab control, which contains two tab pages.
On each tab page, there is a DataGridView, bound to it's own DataTable.
In the RowsAdded event handler for both DGVs, when the first row is added, I resize the columns to fit the data. My handler looks something like this:
private void dgvAllEvents_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)<br />
{<br />
...<br />
dgvAllEvents.AutoResizeColumn(0, DataGridViewAutoSizeColumnMode.DisplayedCellsExceptHeader);<br />
}<br />
<br />
This code works fine for the datagridview that is visible - that is, on the selected tab. However, the column does not get resized on whichever dgv is NOT visible - the tab page that is not selected.
The event is getting fired, I have confirmed that. But the column is not resized when the AutoResizeColumn method is called.
Is there an optimization here that prevents resize from being executed if the column is not visible?
Thanks for any insight you have here.
|
|
|
|
|
I have a bitmap file which I can load into a Bitmap object (or not if i don't have to), but I also have a number of smaller bitmap objects whose images should be sections of the larger image. The co-ordinates (top left, bottom right) of the sections I would like to take are known. I can do this by looping through every pixel needed, using the getPixel method on the larger bitmap, then the setPixel method on the smaller bitmap, however this seems a little bodged, and is probably a bit slow. Is there a better way to do this?
Thanks for any help.
|
|
|
|
|
Still a bit new to the programming, but it looks like the Bitmap.Clone Method is what you might be looking for?
<code>
Bitmap bmpOriginal, bmpSection;
bmpOriginal = new Bitmap("C:\\Test.bmp");
bmpSection = bmpOriginal.Clone(new Rectangle(0, 0, 100, 100), bmpOriginal.PixelFormat);
</code>
-- modified at 16:12 Saturday 6th January, 2007
|
|
|
|
|
you can do the following:
Bitmap newBitmap=new Bitmap(of the right size);
Graphics g=Graphics.FromImage(newBitmap);
and now you can draw anything you like into g, including (part of) an existing image.
Luc Pattyn
|
|
|
|
|
wondering if anyone has some C# code that can verify if SQL is ANSI complaint or not.
tj
|
|
|
|
|
Why does it need to be C# ?
What DB are you using ? Perhaps it has a full ANSI only mode ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi,
I have an unmanaged C++ class, and a managed c++ wrapper for the class. I then access the managed c++ from c# client. The whole thing compiles fine, but when I run the c# client, it crashes as soon as it hits the line where the managed c++ object is initialized. Here is the code that I am working with:
#include <windows.h>
#include <vcclr.h>
#using <System.dll>
using namespace System;
class UnManagedClass
{
public:
LPCWSTR GetPropertyA() { return 0; }
void MethodB ( LPCWSTR ) {}
};
public ref class AdapterNET
{
private:
UnManagedClass * m_unman;
public:
AdapterNET() : m_unman( new UnManagedClass ) {}
~AdapterNET() { delete m_unman; }
protected:
!AdapterNET() { delete m_unman; }
public:
property String ^ get_PropertyA
{
String ^ get()
{
return gcnew String( m_unman->GetPropertyA() );
}
}
void MethodB( String ^ aString )
{
pin_ptr<const WCHAR> str = PtrToStringChars( aString );
m_unman->MethodB( str );
}
};
using System;
using System.Collections.Generic;
using System.Text;
namespace TestingAdapterNET
{
class AdapterNETDriver
{
static void Main( string[] args )
{
AdapterNET _adapterNET = new AdapterNET();
string propA = _adapterNET.get_PropertyA;
_adapterNET.MethodB( propA );
}
}
}
Any ideas?
Thanks,
-----------------
Genaro
|
|
|
|
|
Hi
1) what is "crashes here", what are the symptoms ? any error message, message box, ... ?
2) try putting your managed code inside a try-catch construct, and when you catch
an exception entirely display it. (hint: the Exception.ToString() method gives it all).
3) BTW, how is your C# code to find adapterNET, arent you missing a using statement ?
Luc Pattyn
|
|
|
|
|
Hi and thanks for the response.
1) Crashes here means that I get the following:
No symbols are loaded for any call stack frame. The source code cannot be displayed.
with exception:
{"The specified module could not be found. (Exception from HRESULT: 0x8007007E)":null}
2) I added the try/catch, but it never hits it
3) I included a reference to the dll, and it seems to find the class (since intellisense is available). I have wrapped the c++ code with a namespace and am now '#using' it, just in case.
Any more ideas?
Thanks,
-----------------
Genaro
|
|
|
|
|
Hi,
HRESULT ending on 007E means good old ERROR_MOD_NOT_FOUND, so module not found,
meaning a needed dll file is not found at run-time
If I understand correctly you are using three modules:
1. your main program (C#), being an EXE file
2. your managed C++ adapter class in a DLL
3. your unmanaged C++ whatever, in another DLL
unfortunately it is not clear which module is not found.
I guess (and hope) you have 1. and 2. as two projects within a single solution
in Visual Studio, so it should be perfectly possible to single-step as long as
you do not access anything in 3.
to make sure the managed C++ works, add another class to it, something
that does not need 3. (e.g. a simple function that returns the sum of two integers)
and try using that first;
if that succeeds, continue with the adapter itself.
Luc Pattyn
|
|
|
|
|
I actually have 2 and 3 combined... both managed and unmanaged c++ in the same dll.
I added another managed class to the dll, which just returns the sum of two numbers and does not access any managed code, but I get the same error.
Thanks,
-----------------
Genaro
|
|
|
|
|
Gee, I was not even aware you could do that... But then, I dont use C++, I use
either C#, or C# + unmanaged C with PInvoke.
Maybe the presence of unmanaged code prevents you from calling the managed half of
that mixed dll ??
Luc Pattyn
|
|
|
|
|
Hi Picazo,
Actually, come to think of it; I can not believe you can do that at all.
Please feel free to e-mail me a zip with your solution and stuff, or at least
such combined dll. I would like to look inside it !
Regards
Luc Pattyn
|
|
|
|
|
Hey Luc,
http://sqlite.phxsoftware.com/[^]
These guys to the same, they have combined the original Sqlite3.dll (c only) with a managed C# wrapper.
Supports the Full and Compact .NET Framework as well as native C/C++
The library is 100% binary compatible with the original sqlite3.dll and has no linker dependencies on the .NET runtime for full unmanaged C/C++ development.
And you can get the source
|
|
|
|
|
Thanks a lot, Steve. I will look into that some day.
Seems like picazo should have a look too into that source code...
Luc Pattyn
|
|
|
|
|
Best guess - you have a problem loading the library, because of WinSxS issues. Do you have more than one PC ? My notebook died recently, to the point that a vanilla dll and vanilla C# app would blow up in this circumstance. My own code runs fine on my desktop still.
At the same time, are you sure that all the dlls your code relies on are in the directory of the exe ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi All
the problem is this that i m filling the treeview from the XML File when the form load event occurs the treeview starts making its nodes and child nodes . when I add a node to the XML file it is added but the tree doesnt show it again restarting the application displays the node newly added. I tried the refresh method but I think the problem is this that xmltextreader is forward reader of xml file when the new node is added the cursor is not there which avoids the treenode to make itself updated how to get rid of this problem
SAS
|
|
|
|
|
You have to refresh you TreeView manually by reloading the Xml file. One way to check if the Xml file has been modified is to get the hash code of file, last modified attribute, or store the size in bytes in a long. Then make a timer to check if the values has changed let's say every minute. If there are changes clear all the nodes and reload them again like you did in the load event.
Regards
|
|
|
|
|
Nader Elshehabi wrote: One way to check if the Xml file has been modified is to get the hash code of file, last modified attribute, or store the size in bytes in a long. Then make a timer to check if the values has changed let's say every minute.
Or simply use a FileSystemWatcher component and handle the Changed event
"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
|
|
|
|
|
I don't know why I go the hard way.
Thanks Stefan. Nice catch.
Regards
|
|
|
|
|
Don't think doubleposting will solve your problems.
Best regards!
-Larantz-
|
|
|
|
|
A small addition to the things Nader told you: A simple way to be notified of changes on your XML file is to use a FileSystemWatcher component and handle the Changed event.
"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, I Would like to know how do i read an Excel Document from C#
La Light
|
|
|
|
|
Depending on the version of Excel, you can control Excel via COM, or via .NET. But, you can't read it, on a machine that doesn't have Excel installed, unless it's Office 2007, using the new file format, in which case, the document is a zip that contains XML.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Well, this will only work if your Excel file simply contains Data, no Macros.
Instead of saving as an Excel (*.xls) file, save it as a Tab-Delimited Text File (*.txt)
Then just use a StreamReader to read it as plain text.
|
|
|
|