|
I created a DataGrid and DataTable in code. I set the DataSource of the DataGrid to be the DataTable.
How do I set the alignment of the displayed cell data?
I messed around with the DataGridColumnStyle.Alignment Property but that seemss to only adjust the alignment of the column header. I need to right align the entire column of numbers.
|
|
|
|
|
I use DataGridColumnStyle.Alignment and it works. May be You have extra spaces on right in Your numbers?
Hi,
AW
|
|
|
|
|
Hi
How can i find the position of each of the spaces in this string?
String duh = "Its a beautiful day in the neighborhood";<br />
int c = 0;<br />
char[] s = duh.ToCharArray();<br />
for(int i = 0; i < s.Length; i++)<br />
{<br />
if(s[i].ToString() == " ")<br />
{<br />
c++;<br />
Console.WriteLine(c);<br />
}<br />
}
This code finds the 6 spaces in the string, but i'm having a hard time getting the IndexOf location of each of these spaces.
Any help would be appreciated.
|
|
|
|
|
How about
string s = "It's a beautiful day in the neighborhood";
for (int index = 0; index < length(s); index++) {<br />
if (s[index] == ' ') {<br />
Console.WriteLine(index);<br />
}<br />
}
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
Welcome to CP Julian! Always good to have more Microsofties around.
Hawaian shirts and shorts work too in Summer.
People assume you're either a complete nut (in which case not a worthy target) or so damn good you don't need to worry about camouflage...
-Anna-Jayne Metcalfe on Paintballing
|
|
|
|
|
Thanks for your help on this. it worked as you said, except it's actually
index < s.Length;
also, i was using " " instead of ' ' as you did and i was getting a compilation error. i didn't think it mattered, but i was wrong.
Thanks again.
|
|
|
|
|
I should've added my usual clause:
(Code was written on the fly, probably won't compile.)
The difference between " " and ' ' is that the first is a string of length one, and the second is a single character. So you can't compare a character such as someString[i] to " " (they're two different types)
if (someString[i] == " ") { // won't compile
// blah
}
...but you can to ' ' (since they're both of type char)
if (someString[i] == ' ') { // will compile and do what you think
// blah
}
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
My cheap $0.02:
Option #1:
the same code you have up there, but put the value of i (when s[i] is equal to " ") in a collection (Hashtable, ArrayList, what have you).
Option #2:
use IndexOf(" ") and cut the starting part of the string every time...
string s1 = "Its a beautiful day to be coding";
string s2 = s1; //To save the original s1 if needed
Hashtable ht = new Hashtable(); //Use whatever you need instead of an hashtable
while(s2.Length>0)
{
int k = s2.IndexOf(" ");
if(k<0)
{
break; //No more spaces found
}//IF
ht.Add(ht.Count, k); //Save in ht the index where the next space is found
s2 = s2.Substr(k+1); //Cut away everything up to the space
}//WEND
//Disclaimer: I have not compiled nor tested this code
Maybe it could be better to use a StringBuilder
HTH,
Olorin
|
|
|
|
|
this works fairly well, I subtracted 1 from the for loop
because it prints out 33 for what would be the next space.
This is the output.
4
6
16
20
23
26
<br />
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
string str = "Its a beautiful day to be coding";<br />
string[] strs = str.Split( new char[]{' '} );<br />
int j = 0;<br />
int k = 0;<br />
for ( int i = 0; i < strs.Length - 1; i++ )<br />
{<br />
k = strs[i].Length + 1;<br />
Debug.WriteLine( k + j );<br />
j += strs[i].Length + 1;<br />
}<br />
}<br />
Bo Hunter
|
|
|
|
|
Hi
I'm new to C#. I heard that the .NET runtimes are platfrom independent and applications written in C# can be run on Windows, Linux, etc. But I just read on the mono site that Windows.Forms will be available in future versions of the Linux compiler by emulating them through Wine(ex). So what's the point now? When Windows.Forms will be emulated by Wine, why do I need C# then? Right now Wine can also run C++-Applications that make use of MFC, so what's the point of C#?
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Well, that just doesn't make any sense. Right now Windows can run C++ applications written with MFC too but C# still has its place in Windows.
Same with Linux and Wine.
|
|
|
|
|
In the future I bet there will be full support for the .net framework on *nix, but someone will have to do it. I doubt MS will do the work.
|
|
|
|
|
Greg S. wrote:
So what's the point now? When Windows.Forms will be emulated by Wine, why do I need C# then? Right now Wine can also run C++-Applications that make use of MFC, so what's the point of C#?
Because MFC is not the only tool in the world and Windows.Forms may be about 5% of the .NET Framework.
Acting as a substitute for God, he becomes a dispenser of justice. - Alexandre Dumas
|
|
|
|
|
Maybe it's only about 5% of the .NET Framework, but unfortunately a very essential one if you want to write GUI applications
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I haven't found a clean way to remove a control (say a button) and any associated event handlers. What I do now is delete the control from the form, then find the event handlers in the code, and delete them. When I recompile, I get errors due to the deleted event handler code, and have to perform more surgery to clean them up. I'm new to dotNet, so be kind...
There must be an easier way!
|
|
|
|
|
If you're talking at design time,
then I have run into the same "problem"...
removing a control from the design view removes the declaration and instanciation of that control from the IDE-generated code but not anything related like the even handlers..
..I usually do that by hand.
If you're talking at run time, I think that removing the control from the Controls collection of the form should do the trick (the handlers are still in the compiled code but they will not get called...)
HTH,
Olorin
|
|
|
|
|
Sorry, I was referencing design time. The functionality you reference is what I have seen. It just seems odd that you can't delete the event handlers in one fell swoop.
Oh well.
Thanks for your reply.
|
|
|
|
|
Any handlers added by using the IDE will get removed when you delete the control. If you add handlers by hand then you'll have to remove them by hand as well.
James
"I despise the city and much prefer being where a traffic jam means a line-up at McDonald's"
Me when telling a friend why I wouldn't want to live with him
|
|
|
|
|
What I see is the declaration and instantiation of a control (say a button) is removed when you delete the button, but not any associated event handlers, not even those created with the IDE.
|
|
|
|
|
You can also create a macro to do that for you
|
|
|
|
|
I need to pass a reference to my object
CEmployee
...
CallMyMethod(ref this);
but that doesnt work becuase this is read only.
how would a gain a writable reference to it?
nick
|
|
|
|
|
Alright ladies and gools,
I've got a rather serious question. Does anyone know of any source code sitting around for pdf417 barcode encoding? I've seen some examples out there in c, and maybe one in Java, but I was hoping I might find one in c#.
Thanks in advance for the help,
Ryan
|
|
|
|
|
let me have the com you are using and I'll make it for you.
|
|
|
|
|
I read through the remoting tutorial and the examples they gave were not clear enough. Can anyone tell me if I am setting this up correctly?
I have a class library named RemotingObjectAccess.dll
In the class library are 5 classes that inherit MarshalByRefObject:
myNamespace.PageManager
myNamespace.RuleManager
myNamespace.EventManager
myNamespace.HeaderManager
myNamespace.QuestionManager
If I understand the tutorial correctly:
I run my web in a virtual directory. DONE
I put my DLL and it's dependancies in the bin directory of the web. DONE
I create a remoting.config file and put it in the root of the virtual server. DONE
This is what I have the question on.
I couldn't get the XML to be visible in the post so....assume the XML is correct.
I set the application to my class library name:
application name=RemotingObjectAccess
Under services I defined each class within the library and set the URI to the 'class library name'.SOAP :
wellknown mode="Singleton" type="myNamespace.PageManager" objectUri="RemotingObjectAccess.soap
wellknown mode="Singleton" type="myNamespace.QuestionManager" objectURI="RemotingObjectAccess.soap etc.
and I defined the channel to use the HTTP channel, port 80.
That is my understanding of how I should map my DLL name and individual class names into the various entries in the remoting.config file. Did I understand this correctly???
The documentation also says that the library would not be loaded until the first transaction hits the server. How can I guarantee I get a transaction into the server before I attempt to remotely connect to these classes? Since these are development servers, my remote connection could well be the first transaction!!!
Thanks for any help and input.
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
Hi.
I'm trying to send text to a Epson TM-T88II Reciept printer. the printer is installed as a system printer on win XP.
I've got some drivers from their homepage wich i got to work. the performance however is not acceptable (~30 sec for 20 centimeters).
I tried printing a windows testpage with the MS Generic/Text Only driver. this took ~1 (one!) second for 30 centimeters. So i naturally want to use this driver.
BUT (there is always a 'but'...) When i try to print in my program i get this error:
"The data area passed to a system call is too small".
this is kind of strange since the program has not reacht my printpage event yet....
The program generates the error in system.drawing.printing.OnStartPrint (or something like that) which has nothing to do with anything.. :-/
i've i try a different driver I do not get this error.
I've looked a bit around the web and seen others with similar probs but no solution.
Can anyone help me?!!
here's my code:
---------------------------------
public void PrintBon()
{
try
{
//for text
m_printBon = new PrintDocument();
m_printBon.PrintPage += new PrintPageEventHandler
(this.printBon_PrintBon); <--- Error occurs here. before the program goes to my PrintBon event.
m_printBon.Print();
}
catch(Exception ex)
{
throw ex;
}
}
private void printBon_PrintBon(Object sender, PrintPageEventArgs ev)
{
ev.Graphics.DrawImage(logo, 80, 0, 130, 50);
ev.Graphics.DrawString(m_printString, m_printFont, Brushes.Black, 0, 60);
ev.HasMorePages = false;
}
----------------------
|
|
|
|