|
Hi.
Try this myDataGrid.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
The FoZ
|
|
|
|
|
Thanks but "System.Windows.forms.DataGrid does not contain a definition for 'AutoResizeColumns'"...
|
|
|
|
|
m12 wrote: Thanks but "System.Windows.forms.DataGrid does not contain a definition for 'AutoResizeColumns'"...
You originally said that you had a DataGridView. The error message suggests that you have created a DataGrid.
Alan.
|
|
|
|
|
That's strange... I have just done it and it works...
DataGridView dgv = new DataGridView();
dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
You haven't used 'DataGrid' by mistake have you?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Actually I did, thanks a lot!!
|
|
|
|
|
Make sure you're using the DataGridView control, not the DataGrid control. The DataGrid control was used in .NET 1.x and replaced in .NET 2.0 with the DataGridView control. The old DataGrid control is still in the ToolBox for backward compatibilty with the older control.
|
|
|
|
|
I need to change the default location that my application uses to reference files relatively. I use the syntax as follows: "..\\DBconnection.sec". This returns: C:\Projects\dotnet\RMS_IMCS\RMS_IMCS_WIN\bin\DBconnection.sec. I need the "bin" folder to be changed to RMS_IMCS.
my relative reference needs to look like this: "..\\RMS_IMCS\\RMS_IMCS_WIN\bin\DBconnection.sec".
This would allow me to chnage files located in folders outside my project without having to use absolute referencing. Any help?
|
|
|
|
|
Jacobus01 wrote: my relative reference needs to look like this: "..\\RMS_IMCS\\RMS_IMCS_WIN\bin\DBconnection.sec"
I would highly recommend building a fully qualified path to the file. Using relative paths is problematic because the CurrentDirectory for you app can change without you knowing it. So, get the fully qualified path to your executable, then use the methods in the Path class to manipulate that path to give you the one you want.
|
|
|
|
|
This is a hard thing to do. I have a solution in visual studio 2008 that contains multiple projects. Some are class libraries, some are web apps and some are win apps. Upon deployment I have no idea where all the apps will be located. They will however contain all their needed dlls in the bin folder. Not exactly sure where the web app will keep its dlls. This DBconnection.sec file contains an encrypted DB connection string. I decided to do this to avoid having to recompile the program if the connection string changes and it needs to be encrypted. Somehow my web application and win application needs to know where this file is located. I have a sub system that allows you to create this file but I'm unsure where to store it. How can I solve this issue and make this file available to both the win apps and web apps?
|
|
|
|
|
Each app is going to have it's own app.config for web.config. Class libraries don't get to use their own app.config. They use the config of the application that loads the .DLL.
Since the web app is going to be the most restricted in navigating the file system, the connection string should go in it's web.config file. The other apps can have their own app.config file that has the file path to the web app and can retrieve the connection string from that. I don't know your situation entirely, but I would consider putting the connection string in each config file. I'm just thinking about production and test environments when you might want one or more app(s) might have a different connection string from the others for testing.
|
|
|
|
|
What about encryption? I dont want my client to see the connection string (or any other party for that matter).
|
|
|
|
|
Your encrypting it now, right? It doesn't change.
If your not, then Google for "encrypt connection string" for a ton of examples.
|
|
|
|
|
Hi.
I've been trying to convert a function from an olf VBA project into C#. It uses the Quick Address API to check if a postcode as been recoded. I have managed to delcare the references to the API and managed to perform a search but when I try an retrieve the information it gives me an AccessViolationException. My class is.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace PostCodeRecodetest
{
class QAProClass
{
[DllImport("qapuiek.dll")]
public static extern int QAInitialise(long vi1);
[DllImport("qapuiek.dll")]
public static extern int QAPro_Open(string vs1, string vs2);
[DllImport("qapuiek.dll")]
public static extern void QAPro_Close();
[DllImport("qapuiek.dll")]
public static extern int QAPro_Search(string vs1);
[DllImport("qapuiek.dll")]
public static extern int QAPro_AddrLine(int vl1, int vi2, string vs3, ref string rs4, int vi5);
public string PostCodeRecoded(string postcodeIn)
{
string rsBuffer = "";
int lOpenReturn = 0;
int lSearchReturn = 0;
string sSearchString = "";
string returnedPostcode = postcodeIn;
string iniPath = "C:\\a_DEV\\Qapro.ini";
QAPro_Close();
QAInitialise(1);
lOpenReturn = QAPro_Open(iniPath, "");
if (lOpenReturn != 0) return "QAPro Failed";
sSearchString = postcodeIn;
lSearchReturn = QAPro_Search(sSearchString);
if (lSearchReturn == -9811)
{
lSearchReturn = QAPro_AddrLine(0, 11, "0",ref rsBuffer, 9);
returnedPostcode = rsBuffer;
}
return returnedPostcode;
}
}
}
I have left the old VBA declaration in. I already had some trouble as the DLL is 32 bit and a long was too big for the return values. The QAPro_AddrLine function basically returns a part of the address into rsBuffer from what I can gather. I can't find any documentation on the DLL. What can cause this type of exception?
Any help will be appreciated.
The FoZ
|
|
|
|
|
Hi,
my guess is parameter rs4 is wrong.
The VB code (which you included as a comment, very nice) shows "ByVal" however your C# prototype has a "ref" keyword. Now which is it: the content of a string, or a pointer to a string?
FWIW: for changeable strings, I tend to pass a StringBuilder (with ample capacity preset), then convert to string afterwards using ToString().
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thanks for your reply Luc.
I've have changed the reference back to a val and know the error does not appear (could have sworn it was earlier!) Now I just get nothing back at all!
How would I pass a StringBuilder object to the API when it is asking for a string?
Many Thanks
The FoZ
|
|
|
|
|
1.
change the C# prototype, from "myFunc(..., string rs4, ...)" to "myFunc(...,StringBuilder rs4,...)".
2.
Make sure to create the SB beforehand and give it ample capacity, something like:
StringBuilder sb=new StringBuilder(1000);
myFunc(..., sb, ...);
string rs4=sb.ToString();
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thanks again Luc
One of the things I missed from the VB code is that rsBuffer should be 9 characters in length. Once I changed the to the string builder with a length of 9 I got the correct value returned.
1 function down, 9 to go.
Cheers
The FoZ
|
|
|
|
|
you're welcome.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
TheFoZ wrote: //Declarations
//Declare Sub QAInitialise Lib "QAPUIEK.DLL" (ByVal vi1 As Long)
[DllImport("qapuiek.dll")]
public static extern int QAInitialise(long vi1);
Change the long parameter declaration to an int .
In VBA and VB6 code, the type Long is a 32-bti signed integer. In C# and VB.NET, that's an int , Integer , or System.Int32 .
|
|
|
|
|
Right. I missed that one.
However, it did survive the long/int mistake, showing the one advantage of little-endianness.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Lucky, lucky, lucky...
OT: Am I the only one who thinks of this[^] when I see "little-endianness"??
|
|
|
|
|
Dave Kreskowiak wrote: Am I the only one who thinks...
AFAIK yes you are.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I have made a solution in VS2008 using c# and it's functionality is reading from COM port and monitor the results in some forms and save some of the data in an sql or access database,as well.Now I want make my app as a service to be run before anyone has logged in windows.I have read something about a software but I wanna know how can I do this using .net.
|
|
|
|
|
|
Hey!
I'm trying to remove the AutoIncrement from an MS Access database. I'm using ADOX. The table has two foreign relations, these relations are removed (which works fine), however when I try to remove the Autoincrement property from the column, i receive the following exception :
Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
m_catDatabase.let_ActiveConnection(m_strConnectionString);
foreach (Key keyRelation in m_catDatabase.Tables["Kengetallen"].Keys)
{
if ((keyRelation.Type == KeyTypeEnum.adKeyForeign) && (keyRelation.RelatedTable == "ProductGroep"))
{
m_catDatabase.Tables["Kengetallen"].Keys.Delete(keyRelation.Name);
break;
}
}
foreach (Key keyRelation in m_catDatabase.Tables["Product"].Keys)
{
if ((keyRelation.Type == KeyTypeEnum.adKeyForeign) && (keyRelation.RelatedTable == "ProductGroep"))
{
m_catDatabase.Tables["Product"].Keys.Delete(keyRelation.Name);
break;
}
}
Column clmnProdGroepID = m_catDatabase.Tables["ProductGroep"].Columns["ProductGroep_ID"];
clmnProdGroepID.Properties["Autoincrement"].Value = false;
The last line of code throws the exception.
|
|
|
|