|
Hi,
Try something like:
<br />
Application.CurrentCulture = new System.Globalization.CultureInfo("en-GB");<br />
Do your best to be the best
|
|
|
|
|
How to extend DataGrid so that i can add a property to its column?
|
|
|
|
|
Hello,
I have a problem with a dynamically allocated datagrid whose horizontol scroll bar does not scroll as expected when using the arrow keys. It is jittery but most irritatingly it stops about 50 pixels from scrolling full right.
Can anyone please help?
Kiterq...
|
|
|
|
|
[data]
string sbStrings = @"program files\software\program\report.htm,8/10/2006 4:23 pm-program files\software\program\report.htm,8/10/2006 2:25 pm-program files\software\program\report.htm,6/23/2006 8:14 pm-program files\software\program\report.htm,8/30/2006 1:12 pm";
Q. How would I split this , and - delimited string into a string [,] array?
or use something like this:
ArrayList list = new ArrayList();
list.Add(new ArrayList());
string1 string2
program files\softsoftware\program\help\help3.htm 9/22/2006 2:22 pm
|
|
|
|
|
kvnsdr wrote: Q. How would I split this , and - delimited string into a string [,] array?
<FONT color=Blue>public</FONT> <FONT color=Blue>static</FONT> <FONT color=Blue>string</FONT><FONT color=DarkBlue>[]</FONT> Tokenize<FONT color=DarkBlue>(</FONT><FONT color=Blue>string</FONT> name<FONT color=DarkBlue>,</FONT> <FONT color=Blue>params</FONT> <FONT color=Blue>string</FONT><FONT color=DarkBlue>[]</FONT> delimiters<FONT color=DarkBlue>)</FONT>
<FONT color=DarkBlue>{</FONT>
<FONT color=Blue>for</FONT> <FONT color=DarkBlue>(</FONT><FONT color=Blue>int</FONT> i <FONT color=DarkBlue>=</FONT> <FONT color=Red>0</FONT><FONT color=DarkBlue>;</FONT> i <FONT color=DarkBlue><</FONT> delimiters<FONT color=DarkBlue>.</FONT><FONT color=Teal>Length</FONT><FONT color=DarkBlue>;</FONT> i<FONT color=DarkBlue>++</FONT><FONT color=DarkBlue>)</FONT>
<FONT color=DarkBlue>{</FONT>
delimiters<FONT color=DarkBlue>[</FONT><FONT color=Teal>i</FONT><FONT color=DarkBlue>]</FONT> <FONT color=DarkBlue>=</FONT> Regex<FONT color=DarkBlue>.</FONT>Escape<FONT color=DarkBlue>(</FONT>delimiters<FONT color=DarkBlue>[</FONT><FONT color=Teal>i</FONT><FONT color=DarkBlue>]</FONT><FONT color=DarkBlue>)</FONT><FONT color=DarkBlue>;</FONT>
<FONT color=DarkBlue>}</FONT>
<FONT color=Blue>string</FONT> del <FONT color=DarkBlue>=</FONT> <FONT color=Blue>string</FONT><FONT color=DarkBlue>.</FONT>Join<FONT color=DarkBlue>(</FONT><FONT color=Maroon>"|"</FONT><FONT color=DarkBlue>,</FONT> delimiters<FONT color=DarkBlue>)</FONT><FONT color=DarkBlue>;</FONT>
<FONT color=Teal>Regex</FONT> re <FONT color=DarkBlue>=</FONT> <FONT color=Blue>new</FONT> <FONT color=Teal>Regex</FONT><FONT color=DarkBlue>(</FONT>del<FONT color=DarkBlue>,</FONT> RegexOptions<FONT color=DarkBlue>.</FONT>Compiled<FONT color=DarkBlue>)</FONT><FONT color=DarkBlue>)</FONT><FONT color=DarkBlue>;</FONT>
List<FONT color=DarkBlue><</FONT><FONT color=Blue>string</FONT><FONT color=DarkBlue>></FONT> tokens <FONT color=DarkBlue>=</FONT> <FONT color=Blue>new</FONT> <FONT color=Teal>List</FONT><FONT color=DarkBlue><</FONT><FONT color=Blue>string</FONT><FONT color=DarkBlue>></FONT><FONT color=DarkBlue>(</FONT><FONT color=DarkBlue>)</FONT><FONT color=DarkBlue>;</FONT>
<FONT color=Blue>int</FONT> lastend <FONT color=DarkBlue>=</FONT> <FONT color=Red>0</FONT><FONT color=DarkBlue>;</FONT>
<FONT color=Blue>foreach</FONT> <FONT color=DarkBlue>(</FONT><FONT color=Teal>Match</FONT> m <FONT color=Blue>in</FONT> re<FONT color=DarkBlue>.</FONT>Matches<FONT color=DarkBlue>(</FONT>name<FONT color=DarkBlue>)</FONT><FONT color=DarkBlue>)</FONT>
<FONT color=DarkBlue>{</FONT>
<FONT color=Blue>if</FONT> <FONT color=DarkBlue>(</FONT>m<FONT color=DarkBlue>.</FONT>Index <FONT color=DarkBlue>></FONT> lastend<FONT color=DarkBlue>)</FONT>
<FONT color=DarkBlue>{</FONT>
tokens<FONT color=DarkBlue>.</FONT>Add<FONT color=DarkBlue>(</FONT>name<FONT color=DarkBlue>.</FONT>Substring<FONT color=DarkBlue>(</FONT>lastend<FONT color=DarkBlue>,</FONT> m<FONT color=DarkBlue>.</FONT>Index <FONT color=DarkBlue>-</FONT> lastend<FONT color=DarkBlue>)</FONT><FONT color=DarkBlue>)</FONT><FONT color=DarkBlue>;</FONT>
<FONT color=DarkBlue>}</FONT>
tokens<FONT color=DarkBlue>.</FONT>Add<FONT color=DarkBlue>(</FONT>m<FONT color=DarkBlue>.</FONT>Value<FONT color=DarkBlue>)</FONT><FONT color=DarkBlue>;</FONT>
lastend <FONT color=DarkBlue>=</FONT> m<FONT color=DarkBlue>.</FONT>Index <FONT color=DarkBlue>+</FONT> m<FONT color=DarkBlue>.</FONT>Length<FONT color=DarkBlue>;</FONT>
<FONT color=DarkBlue>}</FONT>
tokens<FONT color=DarkBlue>.</FONT>Add<FONT color=DarkBlue>(</FONT>name<FONT color=DarkBlue>.</FONT>Substring<FONT color=DarkBlue>(</FONT>lastend<FONT color=DarkBlue>)</FONT><FONT color=DarkBlue>)</FONT><FONT color=DarkBlue>;</FONT>
<FONT color=Blue>return</FONT> tokens<FONT color=DarkBlue>.</FONT>ToArray<FONT color=DarkBlue>(</FONT><FONT color=DarkBlue>)</FONT><FONT color=DarkBlue>;</FONT>
<FONT color=DarkBlue>}</FONT>
|
|
|
|
|
Hello everybody.
I'm actually working on a service for phone call notification... However, to achieve that I downloaded a library called CapiThread (this is a sort of wrapper for the capi2032.dll). This is an "old" Win32 dll that exports 5 methods. (InitCapiThread, CloseCapiThread, RegisterNotifyMessage, SetRequest, GetIndication).
To use that dll within a C# Windows-Service project i've written a COM wrapper (COM Object ISDNCapi). The ISDNCapi object retrieves the notifications thrown by the CapiThread dll if an indication is pending and fires an event (OnCapiIndication). There are some other classes to hold the data of the indications and requests.
Okay...
Now i've build a metadata-dll with TLBIMP that i use in my program. (As descripted in "COM Interoperability in .NET Framework: Part I"). The code compiles without any problems, but during the instantiation of my class ISDNCapi the following error raises:
Retrieving the COM class factory for component with CLSID {3A5119AE-E5CC-406F-8F62-FFC340C424CE} failed due to the following error: 80040154.
The component is definetly registered and can access it's dependecies, because instantiation it in VB6 causes no error and the regsvr32 succeeds also.
So what i'm doing wrong?
(While writing this article i'd an idea: I'm using WinXP x64 platform. Could that be the cause of the error? - But i'm definetly compiling for Win32)
I've uploaded the sources of my projects to my server:
CapiWrapperSln
ISDNMonServer
And here are the complete exception details:
System.Runtime.InteropServices.COMException was unhandled<br />
Message="Retrieving the COM class factory for component with CLSID {3A5119AE-E5CC-406F-8F62-FFC340C424CE} failed due to the following error: 80040154."<br />
Source="ISDNMonServer"<br />
ErrorCode=-2147221164<br />
StackTrace:<br />
at ISDNMonServer.ISDNMonServer..ctor() in E:\Entwicklungsumgebung\Projekte\Office\ISDNMon\ISDNMonServer\ISDNMonServer.cs:line 20<br />
at ISDNMonServer.Program.Main() in E:\Entwicklungsumgebung\Projekte\Office\ISDNMon\ISDNMonServer\Program.cs:line 22<br />
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)<br />
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()<br />
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)<br />
at System.Threading.ThreadHelper.ThreadStart()<br />
thanks.
Martin.
|
|
|
|
|
Hi!
The error 0x80040154 means "Class not registered".
Your component itself may be registered, but the error states that the Class Factory (!) could not be retrieved because it's not registered.
Could it be that your COM wrapper is missing this point?
Btw. why do you need the COM wrapper? You can call functions from "legacy" Win32 dlls using P/invoke without having to use a COM wrapper...
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
i thougt i'd already answered... hm, maybe i forgot to post it
i've created the project with the option "component registrar". do i have to call the RegisterAll function of the Registrar class?
in vc 6 i never had to register the class factory separately... so i don't really know what to look for :-> . can you please check it in my sourcecode i've posted before?
i know that i can youse P/invoke. but i've choosen to build a com wrapper, because i want to have a more general solution. so i can use it with other languages... and i found the event handlers better than hooking on notify messages (in C#) the CapiThread.dll sends.
thx.
Martin
|
|
|
|
|
Hi Everybody !
in btnShow_Click() :
try<br />
{<br />
string query="Select * from TestReport";<br />
con.Open();<br />
da=new SqlDataAdapter(query,con);<br />
sqlcmb=new SqlCommandBuilder(da);<br />
da.Fill(DS,"TestReport");<br />
dt = DS.Tables["TestReport"];<br />
dv = dt.DefaultView;<br />
dataGrid1.DataSource=dv;<br />
con.Close();<br />
sqlcmb.Dispose();<br />
con.Dispose();<br />
}<br />
catch(Exception ex)<br />
{ <br />
MessageBox.Show(ex.ToString());<br />
}<br />
}
at the first I have no problem for showing records , but at the second when I press th Show Button , I have this error :
The ConnectionString property has not been initialized !
thanx for any help !
Regards ,
s_mostafa_h
|
|
|
|
|
Hello
Your problem is in this line:
con.Dispose();
You shouldn't dispose the connection if you'll use it again. also I don't recommend opening/closing the connection each time you make a query.
Regards
|
|
|
|
|
hi there ,
but , if it does'nt Dispose() , eachtime , I press the button , all previous records is added again to the end of record .
thanx a lot ,
s_mostafa_h
|
|
|
|
|
Try clearing your data objects explicitly rather than disposing the connection.
|
|
|
|
|
connection(con) has not any property for "Clear()" , Ccan u more explain , plz?;)
s_mostafa_h
|
|
|
|
|
Hello
You shouldn't dispose your connection until you don't need it anymore in the current session. If you want to clear you DataGridView -as I understood from your reply-, then you should call the DataGridView.Rows.Clear() method before filling it again.
Regards
|
|
|
|
|
Nader Elshehabi wrote: You shouldn't dispose your connection until you don't need it anymore in the current session. If you want to clear you DataGridView -as I understood from your reply-, then you should call the DataGridView.Rows.Clear() method before filling it again.
This is what I was getting at - sorry for the lack of detail.
|
|
|
|
|
Hi,
try setting the
con.ConnectionString property
before opening the connection ie, use
con.ConnectionString="your connectionstring";
con.Open();
hope this works.
Nitin...
|
|
|
|
|
I want to be able to select a region of a picture (hover over it with a mouse and select it) and cut out a piece that i selected. I am using the mouseMove event to figure out the position of my pointer, but I am not able to capture the coordinates. I only see the coordinates from when the mouse enters the image and when it leaves. What am I doing wrong?
|
|
|
|
|
I think that a snippet of your code would help here...
Maybe you can post your MouseMove event handler code...?
|
|
|
|
|
Hello
I guess you handled the MouseMove event of your form. Instead you should handle the MouseMove event of your PictureBox or whatever control you're showing the picture in.
If not so, do you lose mouse coordinates when entering the picture, or when leaving it?? ie. Do you track the mouse currently inside or outside the picture??
Regards
|
|
|
|
|
Working on a project that involves generating SVG (Scalable Vector Graphics) charts with C# I have come across the following problem. For reasons of performance I would like to use CSS (Cascading Style Sheets) to represent style properties of SVG elements.
Finally it should look something like that:
<style>
.rectangle
{
fill: blue;
stroke: green;
stroke-opacity: 0.5;
}
</style>
<svg>
<rect x="100" y="40" width="200" height="29" class="rectangle" />
</svg>
A style-area defines all CSS rules which will then be applied in various elements in the SVG document. I'm striving for an elegant solution to represent the CSS properties adequately. Shall I build a few classes representing CSS stylesheets and include these in my classes generating SVG output via composition (see following code snippet).
As you can see the SVG (XML) output is generated via XmlTextWriter class.
<code>
public class SvgElement
{
double x1, x2, y1, y2;
XmlTextWriter writer;
CSSRule rule; // include css rules via composition?
public SvgElement(double x1, double x2, double y1, double y2)
{
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
}
public void Draw()
{
writer.WriteStartElement("line");
writer.WriteAttributeString("class", rule.name);
writer.WriteAttributeString("x1", coordX1.ToString());
writer.WriteAttributeString("y1", coordY1.ToString());
writer.WriteAttributeString("x2", coordX2.ToString());
writer.WriteAttributeString("y2", coordY2.ToString());
writer.WriteEndElement();
}
}
</code>
As I'm lacking to describe my problem precisely, please do not hesitate to comment. I'm more than willing to give further details
Thanks,
Goebel
-- modified at 3:07 Tuesday 22nd August, 2006
|
|
|
|
|
Hi guys.
In my project, I'm opening an MS Excel file and then trying to update some of the cells within it. The only catch however is this particular excel file contains two additional pivottables as well which contain a macro that executes code the instant the excel file is opened.
So, due to the fact that I'm trying update cells at the same time this macro is trying to execute its code, I'm receiving an error which reads:
"Call was rejected by callee"
I've provided my code below. It fails on line 3 ("sheet = MSExcel..."):
----------------------------------------------------
workbook = excel.Workbooks.Open(filePath,0, false, 5, "", "", false, MSExcel.XlPlatform.xlWindows, "",true, false, 0, true, false, false);
sheet = (MSExcel.Sheets)workbook.Worksheets;
worksheet = (MSExcel._Worksheet)sheet.get_Item(currentSheet);
------------------------------------------------------
Apparently, Excel is single-threaded so it can't handle two things at once. I noticed this because while debugging, if I set a breakpoint on my line of code that opens excel and "step into" the next few lines of code, everything works fine (i.e. I gave the macro enough time to execute its code first).
So anyway, I was just wondering if anyone has ever come across this issue before and what can be done to correct it.
Thanks in advance.
-Goalie35
|
|
|
|
|
Here is a hack workaround. So, go ahead and skip this reply if you want a clean solution.
In my experience I've found that Excell/Access/Word Macros are basically hack jobs anyway, so it probably won't hurt much hacking it up some more.
Can you modify the macro that runs when the file is opened every time that you run that code?
Alternatively modify the macro to check for a condition that you set to exit immdediately.
Example:
Step 1.) Modify or remove problem macro
Step 2.) Run your code
Step 3.) Restore problem macro
Step 4.) Possibly run problem macro
|
|
|
|
|
I have a user control that I would like to embed win forms controls in (for example System.Windows.Forms.Button)
I would like to embed the control in a control that is a property on my user control
I do not know how to then make the embedded control paint so that the user can see it.
public class SideBarMenu : UserControl
{
public class MyMenuItem : Control
{
public bool isActive = false;
}
// ... other code omitted
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
//what do I do to paint the child controls
//that can be contained in a MyMenuItem
}
}
public class Test1
{
public static void Test()
{
SideBarMenu mnu = new SideBarMenu();
MyMenuItem i = mnu.AddMenuItem("Hello");
Button b = new Button();
b.Text = "button1";
i.Controls.Add(b);
}
}
|
|
|
|
|
Hello
Maybe I'm not following you! So forgive me if I stray.
You don't have to worry about painting any controls inside your custom control. Just define their sizes and locations and they will draw themselves. You have only to paint your control to be viewd properly to the user, and of course to have a valid size to view all sub-controls.
So in the paint method you only have to paint your control, maybe would want to refresh() or invalidate() all sub-controls and they will draw themselves.
Another event you might want to handle is AddedControl. Have a look at it on MSDN.
Regards
|
|
|
|
|
I have a method:
internal void SetTopic( )
{
}
Using Reflection I want to call it
PropertyInfo method = type.GetMethod("SetTopic", BindingFlags.?);
Which binding flag do I include to find a method with an Internal modifier?
Thanks,
Nick
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|