Similar Threads
1. Log files and cans of worms
2. seeking solution for DataGrid, help, help, help, help
Hi, there;
I have a problem with my datagrid control. I declared it in one of my
form, set with DataGridTalbeStyle as well, and when I click on button, I
would like to retrive Data from Database and bind these data to my datagrid
in the form,
when I click the button first time, it work fine. but when I click the
second button. it report belowing error, I guess it is because it already
set up the column name at first time, so cann't do it on the second time. am
I right?
anyone know how to solve it, I really need help on these.
thanks in advanced.
//========================= Error Details =================================
An unhandled exception of type 'System.InvalidOperationException' occurred
in system.windows.forms.dll
Additional information: The 'NEWS ID' DataGridColumnStyle cannot be used
because it is not associated with a Property or Column in the DataSource.
//==========================================================================
====
//=======================================================================
private void FillDataGrid_News(DataGrid dg,SqlConnection conn,DataSet
ds,string TN)
{
//table name "news"
string SelectCommand = "SELECT * FROM "+TN;
//columns title name
string[] DataGridColumnName = new string[]{"NEWS
ID","TITLE","CONTENT","AUTHOR","DATE","PUB UNTIL"};
DataTable dt= new DataTable(); // datatable for grid
//set data source
dg.DataSource = FillDataTable(DataGridColumnName,dt);
//setting the width
GridColumnStylesCollection colStyle;
colStyle = dg.TableStyles[0].GridColumnStyles;
colStyle[0].Width = 75; // News ID //<<<<<<<<<<<<<<<<<<<<<<Error
point
colStyle[1].Width = 150; // Title
colStyle[2].Width = 250; // Content
colStyle[3].Width = 120; // Author
colStyle[4].Width = 70; // Date
colStyle[5].Width = 70; // Publish Until
//retrive data to the DataSet
ds = retriveDS(conn,SelectCommand,ds,TN);
//fill data to datagrid Row=i, Column=j
for(int i=0;i<ds.Tables[TN].Rows.Count;i++)
{
dt.LoadDataRow(DataGridColumnName,true);
for(int j=0;j<ds.Tables[TN].Columns.Count;j++)
dg[i,j] = ds.Tables[TN].Rows[i].ItemArray[j].ToString();
}
}
3. Need help with C# COM Interop, creating a DCOM server
4. Help with creating an outline area
Hi I am creating a form for vieweing and editing faxes. I read the fax
tiff file into the picturebox. And I have two problems:
1.I want to add a function for the users to be able to select an area
in the picture box and clear it. I am using the Graphics.DrawRectangle
method but the rectangle stays behind the cursor when is moved quickly
eventhough it does draw when releasing the mouse. In the code below I
have the methods used.
2. I would also to create an erase tool like the one in paint any ideas
on how to implement this?
private void peImage_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
//Check if cursor is cross
if(this.peImage.Cursor == System.Windows.Forms.Cursors.Cross )
{
//Checks if its left mouse button
if(e.Button == MouseButtons.Left )
{
structDown = new Point(e.X, e.Y);
structMoveOld.X = e.X;
structMoveOld.Y = e.Y;
blMouseDown = true;
blEndRePaint = true;
}
}
}
private void peImage_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
blEndRePaint = false;
//Check if cursor is cross
if(this.peImage.Cursor == System.Windows.Forms.Cursors.Cross )
{
//Checks if its left mouse button
if(e.Button == MouseButtons.Left )
{
structUp = new Point(e.X, e.Y);
}
}
// Create pen.
Pen blackPen = new Pen(Color.Black);
System.Drawing.SolidBrush sbrushWhite = new SolidBrush(Color.White);
// Create location and size of rectangle.
int intRectWidth = structUp.X - structDown.X;
int intRectHeight = structUp.Y - structDown.Y;
blMouseDown = false;
structUp.X = 0;
structUp.Y = 0;
// Draw rectangle to screen.
//Need to fill with a brush
Graphics g = this.peImage.CreateGraphics();
g.DrawRectangle(blackPen, structDown.X, structDown.Y, e.X -
structDown.X, e.Y - structDown.Y);
g.Dispose();
}
private void peImage_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if(this.peImage.Cursor == System.Windows.Forms.Cursors.Cross &&
blMouseDown == true)
{
if(blEndRePaint == true)
{
if(structMoveOld.X > e.X && structMoveOld.Y > e.Y)
{
//Making Smaller
//Delete the vertical leftovers
this.peImage.Invalidate(new Rectangle(structMoveOld.X+1 ,
structDown.Y, -(structMoveOld.X -e.X), e.Y));
//Delete the vertical leftovers
this.peImage.Invalidate(new Rectangle(structDown.X ,
structMoveOld.Y+1, e.X, -(structMoveOld.Y -e.Y) ));
blRepaint = true;
this.peImage.Invalidate(new Rectangle(e.X , e.Y, -
(structMoveOld.X -e.X), - (structMoveOld.Y -e.Y)));
//Console.Write("Old X: " + structUp.X.ToString() + " New X: " +
e.X.ToString() + "\r\n");
}
else if(structMoveOld.X < e.X && structMoveOld.Y < e.Y)
{
//Growing
blRepaint = true;
this.peImage.Invalidate(new Rectangle(structDown.X+1,
structDown.Y+1, e.X - structDown.X-1, e.Y - structDown.Y-1));
//Console.Write("Incr Old X: " + structDown.X.ToString() + " Incr
New X: " + e.X.ToString() + "\r\n");
}
structMoveOld.X = e.X;
structMoveOld.Y = e.Y;
//Console.WriteLine("MouseMove");
}
}
}
private void peImage_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
if(blRepaint == true)
{
Pen blackPen = new Pen(Color.Red);
blackPen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot;
Graphics g = this.peImage.CreateGraphics();
g.DrawRectangle(blackPen, structDown.X, structDown.Y,
structMoveOld.X - structDown.X, structMoveOld.Y - structDown.Y);
g.Dispose();
//Console.WriteLine("ImagePaint");
}
blRepaint = false;
}
Thanks in advance for the help
5. need help to create C#-music Inventory Program - CSharp / C#
6. HELP: ASP.NET Web Application, Impersonating User and Creating Threads via C++ COM Object
Sorry for the long subject, but it summarizes my issue nicely.
I have an ASP.NET application running ... it's a web app running under IIS.
For the purposes of allowing this app to access network resources,
web.config specifies a network login and sets "impersonate" to true.
Ok, so this code has to make use of some COM objects written in C++. One of
these C++ objects has to, under certain conditions, spawn a thread to do
some work. The spawned thread's user is ASPNET, not the impersonated user
of the parent thread. Help!
GetUserName returns ASPNET when invoked from inside the new thread. The
same call returns the correct login when called from the parent thread.
Ah! I thought this was simply a matter of setting up a SECURITY_ATTRIBUTE
with one of the DACL's I've used elsewhere. I saw THREAD_IMPERSONATE and
THREAD_DIRECT_IMPERSONATION as access flags. So I added code for this.
Yet, everything I tried failed to solve the problem. Reading further, the
docs seem to indicate that the original NULL passed as the security
attribute pointer should have inherited the parent's DACL. But then, I want
to be the same USER as my parent, and DACL's aren't it, really.
I've seen examples of actually logging in via API using a user, password and
domain. But I don't have the password ... it's obfiscated in the web.config
(well, my test case isn't, but real life will encode it and use the registry
to store it).
Can anyone point me in the right direction? How do I get my new thread to
be logged in with the user of its parent, please?
Thanks in advance,
Nick
7. any help appreciated in creating c# functions for RasEnumConne
8. any help appreciated in creating c# functions for RasEnumConnections and RasHangUp
Hi there,
i've tried and tried and just cannot get this working, i want to create a
function in c# that calls the RasEnumConnections and loop through the items,
when i find the one i'm after, then i call RasHangUp on it to disconnect it.
This is what i have so far (sorry if any mistakes here, this is my first
real attempt at API calls)...:
--------------------------------------------------------------
[DllImport("coredll.dll")]
private static extern int RasEnumConnections(ref RASCONN[] lprasconn, ref
uint lpcb, ref UIntPtr lpcConnections);
[DllImport("coredll.dll")]
private static extern int RasHangUp(string session); //not sure here so so i
put string, but i think it needs a handle.
[StructLayout(LayoutKind.Sequential)]
public struct RASCONN
{
public uint dwSize;
public UIntPtr hrasconn;
public string szEntryName;
}
--------------------------------------------------------------
.....the rest i'm not too sure of in how to initialize it all and make the
API call to RasEnumConnections....
Any help with source code examples would be reeeallly appreciated :-))
thanks in advance,
Paul