|
sorry, here is my coding. thanks
SQL = "SELECT * FROM TABLE ORDER";
cmd = new System.Data.OleDb.OleDbCommand (SQL, conn);
adapter = new System.Data.OleDb.OleDbDataAdapter(cmd);
ds = new System.Data.DataSet();
adapter.Fill(ds,"TABLE");
dataGrid1.DataSource = ds;
dataGrid1.DataMember ="TABLE";
CurrencyManager cm = (CurrencyManager)dataGrid1.BindingContext[dataGrid1.DataSource,dataGrid1.DataMember];
string myVariable;
if (cm != null)
{
DataRowView rowView = cm.Current as DataRowView;
if (rowView != null)
{
myVariable = rowView["startDate"].ToString();
}
}
Chris
|
|
|
|
|
sorry there was some typo error..
SQL = "SELECT * FROM TABLE";//<-- without "Order"
cmd = new System.Data.OleDb.OleDbCommand (SQL, conn);
adapter = new System.Data.OleDb.OleDbDataAdapter(cmd);
ds = new System.Data.DataSet();
adapter.Fill(ds,"TABLE");
dataGrid1.DataSource = ds;
dataGrid1.DataMember ="TABLE";
CurrencyManager cm = (CurrencyManager)dataGrid1.BindingContext[dataGrid1.DataSource,dataGrid1.DataMember];
string myVariable;
if (cm != null)
{
DataRowView rowView = cm.Current as DataRowView;
if (rowView != null)
{
myVariable = rowView["startDate"].ToString();
}
}
Chris
|
|
|
|
|
I'm not sure if you're posting just snippets from various methods or if this is your entire method. If the latter is true, then of course it won't work. You need to declare myVariable (and I certainly hope you haven't given it that non-descript name) as a field (so you don't loose it after setting it) and put everything below that in your code snippet in an event handler for DataGrid.RowHeaderClick (which means you'll have to extend DataGrid with your own control since RowHeaderClick is protected), or just handle the Click event, like so:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
public class Form1 : Form
{
private DataGrid dataGrid1;
private Label label1;
private SqlCommand sqlSelectCommand1;
private SqlConnection sqlConnection1;
private SqlDataAdapter sqlDataAdapter1;
private DataView dataView1;
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
DataSet ds = new DataSet();
sqlDataAdapter1.Fill(ds);
dataView1 = new DataView(ds.Tables[0]);
dataView1.AllowDelete = false;
dataView1.AllowEdit = false;
dataView1.AllowNew = false;
dataGrid1.DataSource = dataView1;
}
private void InitializeComponent()
{
this.dataGrid1 = new DataGrid();
this.label1 = new Label();
this.sqlSelectCommand1 = new SqlCommand();
this.sqlConnection1 = new SqlConnection();
this.sqlDataAdapter1 = new SqlDataAdapter();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
this.dataGrid1.Anchor = ((AnchorStyles)((((AnchorStyles.Top | AnchorStyles.Bottom)
| AnchorStyles.Left)
| AnchorStyles.Right)));
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(8, 8);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(280, 208);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.Click += new System.EventHandler(this.dataGrid1_Click);
this.label1.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left)
| AnchorStyles.Right)));
this.label1.Location = new System.Drawing.Point(8, 224);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(280, 23);
this.label1.TabIndex = 1;
this.sqlSelectCommand1.CommandText = "SELECT ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice" +
", UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued, CategoryName FROM [Alp" +
"habetical list of products]";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlConnection1.ConnectionString = "workstation id=ALICE;packet size=4096;integrated security=SSPI;data source=\".\";pe" +
"rsist security info=False;initial catalog=Northwind";
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new DataTableMapping[] {
new DataTableMapping("Table", "Alphabetical list of products", new DataColumnMapping[] {
new DataColumnMapping("ProductID", "ProductID"),
new DataColumnMapping("ProductName", "ProductName"),
new DataColumnMapping("SupplierID", "SupplierID"),
new DataColumnMapping("CategoryID", "CategoryID"),
new DataColumnMapping("QuantityPerUnit", "QuantityPerUnit"),
new DataColumnMapping("UnitPrice", "UnitPrice"),
new DataColumnMapping("UnitsInStock", "UnitsInStock"),
new DataColumnMapping("UnitsOnOrder", "UnitsOnOrder"),
new DataColumnMapping("ReorderLevel", "ReorderLevel"),
new DataColumnMapping("Discontinued", "Discontinued"),
new DataColumnMapping("CategoryName", "CategoryName")})});
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(296, 253);
this.Controls.Add(this.label1);
this.Controls.Add(this.dataGrid1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
static void Main()
{
Application.Run(new Form1());
}
private void dataGrid1_Click(object sender, EventArgs e)
{
CurrencyManager cm = (CurrencyManager)dataGrid1.BindingContext[
dataGrid1.DataSource, dataGrid1.DataMember];
if (cm != null)
{
DataRowView view = cm.Current as DataRowView;
if (view != null)
label1.Text = view[1].ToString();
}
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I'm trying to control FlashGet using COM in my .NET application. I made a wrapper class of the jccatch COM server. I create an instance of the JetCarNetscapeClass defined in the wrapper class. The method AddUrl works fine - it has three string parameters. The problem comes from the AddUrlList method. In the original declaration in the COM server it has a VARIANT* pList parameter, and the wrapper class marshalizes it as ref object pList. So, when I pass an array or ArrayList of strings, an exception is thrown. What kind of parameter should I pass to the method or how can I change the default marshalizing behavior? I couldn't find a solution and I searched a lot.
|
|
|
|
|
And ArrayList will not marshal the same as an array of strings. What you passed to the interop'd method AddUrlList depends on what the documentation states.
More than likely you must pass it a SAFEARRAY . Since you created an interop assembly (RCW) using VS.NET or tlbimp.exe, you've lost the opportunity to define the correct UnmanagedType to the MarshalAsAttribute , namely the UnmanagedType.SafeArray type. You can, however, re-declare the same interface yourself with the ComImportAttribute and the correct GuidAttribute and ComInterfaceAttribute (with values the same as the one in the interop assembly). If you read the documentation for the UnmanagedType.SafeArray you should get some idea of how to marshal the string[] array correctly.
You could also try using Marshal.GetNativeVariantForObject , but you'll need additional methods from the Marshal class to marshal the returned IntPtr correctly as an object . The method above would probably be easier (you won't have to marshal the data yourself; .NET will do it for you).
Again, though, this all depends on what the AddUrlList is expecting. If you were to tell us what the API documentation states (not what tlbimp.exe or VS.NET thinks it should be in the interop assembly), that will most likely help.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
I'm trying to add a context menu to my form that would contain only items that can be checked. I would like the context menu to stay open when the user clicks an item. This way, they wouldn't need to re-open the context menu to check 5 or 6 items at once.
So basically, open the context menu, check a few items, then click out of the context menu to close it.
Is it possible? I thought about reopening the menu after every click but that seems like a stupid solution (and the flickering is ugly).
Thanks!
Carl
|
|
|
|
|
Using the MenuItem and derivative classes defined in the .NET BCL, no. These encapsulates the native menu APIs in a basic manner.
You'll either need to figure out an alternative UI (like a popup (modal) dialog to check the options, which are still reflected upon by the menus (so they share data)) or use a third-party library (or develop your own menu'ing systme).
In .NET 2.0, the menus and toolbars as you know them are dead. Well, not dead (you can still use them) but superceeded by Winbars which look and act very much like Office menus and toolbars, so you can site about any control you want on them, including a simple borderless dialog that doesn't go away until dismiss (you have control over what happens). These are not constrained by the current menu APIs.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Heath,
Thanks for your answer. That sounds like a lot of work for the benefits (since the users would have used this feature only once in a while).
Thanks again!
Carl
|
|
|
|
|
Carl,
I don't think what Heath is suggesting would take alot of work. Just do this:
1) Hook into the MouseClick event and see if the right mouse has been clicked.
2) Create a simple form with the checkboxes and make it a non-sizable dialog.
3) The user checks to their hearts content then clicks the OKAY button
4) You process the results. Voila, you replace the context menu with what you need!!!
There are 10 kinds of people in the world.
Those that read binary...
...and those who don't.
|
|
|
|
|
That may seem like a stupid solution, but it may be the only one you have. You are trying to change the nature of a context menu (or any menu for that matter). You either need to create your own control from scratch or you could just create a small dialog box with checkboxes instead. Just create a selection in your current context menu that says "Set Options", and then open a dialog box with your checkboxes in it when that option is selected. I know this isn't the answer you're looking for, but I can't think of any way to override context menu behaviour without some inelegant hack that, from a useability perspective, probably shouldn't be done anyhow.
Best Regards.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
I’ve got a problem. That is, when we use those Windows APIs,such as SetupDiGetClassDevs() and SetupDiEnumDeviceInterfaces(),
to enumerate all the instances of the usb device class, what I wanna make sure are the answers to these questions:Is there a certain
rule which determines the order of being enumerated among all the instances? In other words,If we can depend on a certain rule to
foreknow which device instance will be enumerated first,which will be the next and which will be the last? If there is,then what
it is? If not,how can we let the first attached one be first enumerated,the next will be next,and the last will be last?
|
|
|
|
|
Your question has absolutely nothing to do with C#. You need to either read the documentation for the functions you're P/Invoking (in the Platform SDK at http://msdn.microsoft.com/library[^]) or pack the returned data into an array in C# and sort it using Array.Sort and an IComparer implementation (like Comparer.Default which works for the intrinsics and strings).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi...
I want my Application to run when windows start..!
I didn't know how to do it, so i searched the registry on my computer and found the key i think was the right ("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run")
I tried to do this...
string path = Environment.CurrentDirectory + "\\MyApp.exe";
RegistryKey App = Registry.LocalMachine;
RegistryKey App = App.OpenSubKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\");
App.SetValue("MyApp", path);
But that did not work.... it throws a "'System.NullReferenceException' -
Additional information: Object reference not set to an instance of an object."
Then I tried this....
string path = Environment.CurrentDirectory + "\\MyApp.exe";
Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Run").SetValue("MyApp", path);
But it also thorws an error -> "'System.UnauthorizedAccessException' occurred in mscorlib.dll - Additional information: Cannot write to the registry key."
I have no idea what to do then!
Can anyone help me how to write to the registry or tell me a way so my application will run when windows start?
Thanks...!
QzRz
|
|
|
|
|
Put a shortcut in the startup folder of the start menu.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
I dont understand what you mean...
is there a folder i can put a shortcut in so it automaticly will run it when windows start..?
if that is what you mean.... how can i find it...? (need to find it also if it is not on same drive on every computer)
QzRz
|
|
|
|
|
Click 'Start', go up to 'Programs', and expand the list if necessary. There's a folder there called 'Startup'. An install program should allow you to put a shortcut there, or alternatively, the folder structure is stored at <current user documents and settings location>\Start Menu\Programs\Startup. There are functions that help you find the location of special folders like the one windows is in, or the one where your documents and settings live.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
LOL. How can someone not know about this???
Alex Korchemniy
|
|
|
|
|
Adding to what Christian has said, the Startup folder executes everything in it when a user logs in, NOT when Windows starts. The same thing is true for the Run key your trying to use. The only way to get an application to start when Windows starts (and will run even if a user is not logged in) is to write your application as a Service.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
OKay.... but if I wants it to write a value to the registrykey, then is there a way for me to do that...?
QzRz
|
|
|
|
|
Using the original code you posted, take the two backslashes off the end of the path to the Run key:
string path = Application.StartupPath + "\\MyApp.exe";
RegistryKey App = Registry.LocalMachine.OpenSubKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
App.SetValue("MyApp", path);
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Well.... it still doesn't work... still it gives me a "'System.NullReferenceException' - Additional information: Object reference not set to an instance of an object."
The code looks like...
string path = Environment.CurrentDirectory + "\\MyApp.exe";
RegistryKey AppA = Registry.LocalMachine;
// Change the next line. Remove the two backslahes from the end of 'Run'...
RegistryKey App = AppA.OpenSubKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
App.SetValue("MyApp", path);
QzRz
|
|
|
|
|
My fault. There are a couple of problems, and are easily corrected if you, or I, would read the documentation on the RegistryKey class.
using System.Io;
using Microsoft.Win32;
string path = Path.Combine( Application.StartupPath, "MyApp.exe" );
RegistryKey myKey = Registry.LocalMachine.OpenSubKey( @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true );
myKey.SetValue( @"MyApp", path );
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks.... it works perfect now!
QzRz
|
|
|
|
|
I am writing an application that accesses a web page (the first page) with an httpget to retrieve the first page, issues an httppost with selection data and cookie from the first page httpget to retrieve a second page, then retrieves subsequent third pages with httpgets based on links in the second page. These third retrieves fail in the C# application.
If I use IE or Mozilla to make these third page retrieves, a proxy sniffer shows that on the third retrieve some additional data has been added to the cookie. The proxy sniffer also shows that some javascript routines have been downloaded on the first page retrieve and looking at the source from the second page retrieve it seems that it is one of these javascript routines that is adding the data to the httpget for the third page.
So in my C# application, what happens to the downloaded javascript routines and how do I access and run them in the same way my browsers do this?
Jerome K Jerome
|
|
|
|
|
The javascript files get downloaded the same was as everything else: data. What happens with the data is completely up to the client (your code).
Internet Explorer actually hosts the scripting engines (JScript, VBScript, and any other third-party scripts like PerlScript from ActiveState[^]). This doesn't happen just by downloading data (actually, nothing happens just by downloading data no matter what the client is - it's just a stream of bytes).
Hosting the scripting engines in such a way that you can simulate what the browser does is more complicated than you could probably imagine. Not only do you have to implement the interfaces that the browser does (practically all the interfaces defined by both mshtml.dll and shdocvw.dll, but many, many other COM interfaces (i.e., you can't just implement these interfaces: they don't exist in .NET), not to mention the Windows Script Host interfaces. Believe me, as part of the team that develops and sustains Windows Script I can assure you that's it's a complicated and very long job that you may not want to emark on! If you do, you must completely understand COM interop, P/Invoke, and data marshaling between unmanaged and managed code, and understand COM and OLE and how COM clients and servers interact through sites, threading models, and more.
Your best bet is to use inflection to determine what the script file would do by detecting certain patterns.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|