|
Thanks Lukeer!!!
I tried your suggestion, missed somewhere.
Appreciate if you can help me draw three lines with numbering on them according to the order of drawing them.
I wish to have origin in the center of the window and all points should be given according to that. Y-axis should be positive in the upward direction and negative in the downward direction.
Thanks,
Praveen Raghuvanshi
Software Developer
|
|
|
|
|
Here is a quick proposal with horrible readablility:
private PointF Transform(PointF logicalPoint)
{
float logicalXMin = -100;
float logicalXMax = 100;
float logicalYMin = -100;
float logicalYMax = 100;
float canvasXMin = this.ClientRectangle.Left;
float canvasXMax = this.ClientRectangle.Right;
float canvasYMin = this.ClientRectangle.Top;
float canvasYMax = this.ClientRectangle.Bottom;
float canvasX = ((((float)(Math.Log(logicalPoint.X, 10))) - logicalXMin) / (logicalXMax - logicalXMin) * (canvasXMax - canvasXMin)) + canvasXMin;
float canvasY = ((-logicalPoint.Y - logicalYMin ) / (logicalYMax - logicalYMin) * (canvasYMax - canvasYMin)) + canvasYMin;
return (new PointF(canvasX, canvasY));
}
You use a control as canvas. You have to transform logical co-ordinates into canvas co-ordinates. Therefore you look at your logical value in relation to logical maximum and minimum. Then apply the same relation to canvas minimum and maximum.
Since canvas Y-axis is inverted, you have to use negative logical Y value to compensate.
As mathematics dictates, you can't use negative X values here.
Draw grid lines using logical co-ordinates. They should get processed just as any data point.
for( int power = 0, power < 4, power++)
{
g.DrawLine( gridPen, Math.Pow(1, power), logicalYMin, Math.Pow(1, power), logicalYMax);
g.DrawLine( gridPen, Math.Pow(2, power), logicalYMin, Math.Pow(2, power), logicalYMax);
g.DrawLine( gridPen, Math.Pow(5, power), logicalYMin, Math.Pow(5, power), logicalYMax);
} Horizontal grid lines should be even easier.
for( int i = logicalYMin; i <= logicalYMax; i += 10)
{
g.DrawLine( gridPen, logicalXMin, i, logicalXMax, i);
}
Ciao,
luker
modified on Wednesday, July 13, 2011 7:17 AM
|
|
|
|
|
Thanks, I will give a shot.
Praveen Raghuvanshi
Software Developer
|
|
|
|
|
As Lukeer says, you should calculate the canvas position from chart coordinates yourself. Using translate and scale seems clever but as you've discovered it causes text to be drawn upside down as well.
When I draw a log chart I still place gridlines linearly but label them logarithmically (e.g. 0.5, 1, 2, 4, or 1, 10, 100, 1000). I find the 'log graphpaper' approach to be fussy and generally not helpful. But if you want to do that then it is easy enough to calculate the appropriate chart coordinate Y values (log y at sensible Y values such as 1, 2, 5 each power of 10), and then you can transform those like all the other things for drawing.
|
|
|
|
|
XMLTextReader has a depth property that returns the depth of the current node. Anyone know a way to determine the maximum depth? I guess I could read through the file first, but that doesn't seem very efficient.
Everything makes sense in someone's mind
|
|
|
|
|
Until you read through the file, the XML reader wouldn't know anyway (even if, as another example, you used an XPathNavigator to search only leaf nodes). But a better question is why you need to find depth? Because to do so may be considered inefficient, maybe first you should determine if you really need to.
This posting is provided "AS IS" with no warranties, and confers no rights.
Program Manager
Visual Studio Professional Deployment Experience
Microsoft
[My Articles] [My Blog] [Follow on Twitter]
|
|
|
|
|
XML doesn't include structure metadata in a header or anything, so to find the maximum depth you would have to read the whole document and check every node.
|
|
|
|
|
I googled and found none... according to MSDN, in framework 4, there is vertical alighment property available (see [RichTextBox Property]). Not sure how I can get that implemented.
Pls 'F1'!
|
|
|
|
|
Hello Blubbo,
property of vertical alignment of text on RichTextBox control is not available,
Bye
Carmelo La Monica
modified on Tuesday, July 12, 2011 3:06 PM
|
|
|
|
|
Oh, the link I provided was for the cellphone (something like that).... so is there a such way to do that anyway?
|
|
|
|
|
Hello blubb,
the link you posted refers to if you use WPF, what technology you're using?
Bye
Carmelo La Monica
|
|
|
|
|
Visual Studio c# for windows (not WPF)
|
|
|
|
|
Okay, so I'm thinking my problem here probably involves completely misunderstanding the use of a DataGridView, but here goes:
I'm currently working on learning how to use SQL with C#/.NET using VS2010. I created a DataGridView that's linked to my data table. Adding rows to the DataGridView while the program was running did not actually save the changes to the database, so I created a separate piece using SqlConnection & SqlCommand. This successfully added the rows to the database, but did not update the DataGridView.
So I suppose there are two questions here: How do I save the changes to a DataGridView to the bound data table? and How do I have the DataGridView reload table data?
|
|
|
|
|
While this most definitely doesn't answer your question, here goes:
Don't use DataGridViews to enter/introduce/edit data. Use dedicated windows/forms.
You're life gets a whole lot easier.
The reasons are plenty: more control(like data validation), easier to debug, the app looks nicer...
I only use DataGridViews for displaying data(if that).
All the best,
Dan
|
|
|
|
|
Good to know. Given that I'm at this point just trying to figure out how to use SQL in C#, it's good to know which pieces to avoid. So yes, that answer was useful, even if it didn't actually answer my specific question.
|
|
|
|
|
The updating is usually handled by a DataAdapter.Update -- but as has been said, you won't have a very impressive app.
|
|
|
|
|
I have been struggling HARD to find a solution to this. In order to get some long-term platform compatibility (PC simulator, embedded target, etc.) I am implementing my main code in C, and a GUI emulator in C# as a DLL.
I am able to make calls into the C# DLL from my native code by exposing the DLL functions as COM objects (I think...). Data are passed in and out of the library functions just fine.
I would like to have callbacks made back to the native code when events are triggered in the C# code. You can imagine that when a button is clicked on my fancy C# GUI, my native code gets called. I cannot seem to get this callback mechanism working.
Can anyone please give an example, syntax, etc. for assigning a native callback to a managed C# event (or something like that)?
There are TONS of examples of using managed code to call un-managed DLLs, but very little going to the other way.
Thanks in advance.
-Stuart
|
|
|
|
|
Stuart, you need to expose your event as described in this[^] example. This creates the COM hookup for the event handler that you can reference through your C code.
|
|
|
|
|
Nice one - I think that is going to come in handy to me some day too.
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
Peter, this is helpful, but at least half of the challenge is on the native (un-managed) side. I think now I have a syntactic problem with registering my native C function with the managed event.
Any more tips?
Thanks!
|
|
|
|
|
That side is going to require you to hook up to the COM event in your C code. You might want to read this[^] article to see how C++ handles it (it should be easy enough to apply this to C).
|
|
|
|
|
"Calling" the managed functions isn't really a problem anymore. The real problem is passing in a reference to the unamanged event handler function into the managed event. Sorry to keep pushing on this, but does sound like you know what you're doing!
Thanks again.
|
|
|
|
|
Have you assigned the IConnectionPoint interface[^]? As you've implemented the event interface in your C#, the CLR Interop automatically applies the juice that hooks this together.
|
|
|
|
|
Hi all I have a problem i am importing data from an excell spreadsheet to a sql 2008 database ,and i can do that in c# 3.5 getting all fields in the spreadsheet the same as the ones in the db..
I want to select now a few fields and insert them or rather import them to the database not all fields are the same here heres my code and i am getting this error
" The connection was not closed. The connection's current state is open."
i want only these 2 fields(DOC_TPL_CGY_TP_DESC ,USR ) from excell now to dbs the other two i will insert namually please help
private void btnDocumentCat_Click(object sender, EventArgs e)
{
string oconn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\2010Projects\\Project1\\DocumentCatalogue\\bin\\Debug\\MyExcelFile.xls;Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=1\";";
OleDbConnection con = new OleDbConnection(oconn);
string filepath = @"C:\\2010Projects\\Project1\\DocumentCatalogue\\bin\\Debug\\MyExcelFile.xls";
string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + filepath + ";" + "Extended Properties=Excel 8.0;";
using (OleDbConnection cn = new OleDbConnection(ConnectionString))
{
cn.Open();
DataTable dbSchema = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
if (dbSchema == null || dbSchema.Rows.Count < 1)
{
throw new Exception("Error: Could not determine the name of the first worksheet.");
}
string WorkSheetName = dbSchema.Rows[0]["TABLE_NAME"].ToString();
OleDbCommand ocmd = new OleDbCommand("SELECT * FROM [" + WorkSheetName + "]", cn);
OleDbCommand OCM = new OleDbCommand("SELECT DOCUMENT NAME ,USER FROM [" + WorkSheetName + "]", con);
DataTable dt = new DataTable(WorkSheetName);
OleDbDataReader odr = OCM.ExecuteReader();
//OleDbDataReader URD = OCM.ExecuteReader();
string DOC_TPL_CGY_TP_DESC = string.Empty;
string DOC_TPL_CGY_TP_CODE = string.Empty;
int DOC_TPL_CGY_TP_ID = 0;
string USR = string.Empty;
while (odr.Read())
{
// DOC_TPL_CGY_TP_CODE = valid(odr, 0);
DOC_TPL_CGY_TP_DESC = valid(odr, 0);
USR = valid(odr, 1);
Insertdataintosql2(DOC_TPL_CGY_TP_CODE,DOC_TPL_CGY_TP_DESC,DOC_TPL_CGY_TP_ID, USR);
}
}
}
private void Insertdataintosql2(string DOC_TPL_CGY_TP_CODE, string DOC_TPL_CGY_TP_DESC, int DOC_TPL_CGY_TP_ID, string USR)
{
throw new NotImplementedException();
}
sipho
|
|
|
|
|
That code sure is hard to read without PRE tags.
Which line is giving the Exception?
Why use @ and \\ ?
What are the DataTable dt and OleDbCommand ocmd used for?
Is the connection to the destination database open?
|
|
|
|
|