|
Hi,
I desperatelly need an answer on my probably dumb question .
I use data bound DataGridView control and I need (on click of the button) to programmatically add row. When I use command DataGridView1.Rows.Add() I get message: "Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.". How can I trigger event that causes to create new row?
Thanks,
Aleks
|
|
|
|
|
Add a row to the datatable that is the source, and remove it later.
------------------------------ "The Soapbox has been so ..."
|
|
|
|
|
So simple and so smart. Thanks a lot.
|
|
|
|
|
I am currently trying to build a serial monitoring program.
I am planning on using several ChildMDI forms to hold data grids with decoded serial data. I built an event driven serial driver, and when a packet is received, an event is fired. From that eventhandler, I am trying to call methods within the ChildMDI forms to update their data. When the event fires, everything is executed, except the calls to the ChildMDI forms. Its as if the calls are never made (I have tried one of the methods I wrote, and just using .Close() to no avail). I have verified the methods work by inserting a test button and have gotten the Child forms to respond to that. Is this something that just won't work, or do I need to configure it in a special way?
Thanks!
-- modified at 15:15 Friday 16th February, 2007
|
|
|
|
|
I have an application that frequently modifies the values of certain strings that are attributes of some classes that I use in the application. These strings get modified once every 1-4 minutes during normal software operation. Would the StringBuilder class provide any performance enhancement over a String in this situation?
Thanks.
|
|
|
|
|
Have you tried testing this yourself using the stopwatch class of the System.Diagnostics namespace (should be the correct namespace)?
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Probably not. You incur a hit at three times with a StringBuilder: initialization, ensuring capacity (internal), and calling ToString. I'm guessing you'd be calling ToString too frequently to be a real benefit.
That being said, you definitely need to test it to be sure. Start with the easiest, reasonable implementation and then if the performance is an issue then examine other alternatives.
|
|
|
|
|
I personally have noticed a large difference in performance but then I wasnt building and displaying constantly. I was doing more batch text processing.
Cleako
|
|
|
|
|
Hi,
StringBuilder will show much better performance than string when you need to calculate complex string expressions as in:
string s="the alphabet consists of ";
foreach (char c in "abc...z") s=s+c;
Inside the loop each s=s+c; will create a new string, copy the existing characters and append
one (that is a quadratic operation: when the number of iterations doubles, the cost
will quadruple).
With StringBuilder nothing gets copied as long as the StringBuilder's capacity is
sufficient. So I would say if there are fewer than 3 to 5 operations, string will be faster;
in my example StringBuilder will win hands down; and yes it helps to give it adequate
initial capacity.
Luc Pattyn
|
|
|
|
|
Just to echo the others in the forum, you really need to do testing to be sure. Hook up a performance counter to figure out if it's bottlenecking your application.
That being said, it sounds like your code isn't doing enough work to warrant using StringBuilder objects. Are you modifying only a handful of strings every 1 - 4 minutes? If so, is it worth it to you to optimize away a few milliseconds out of every few minutes?
|
|
|
|
|
I am trying to compress a jpg file in the same manner that you would set the quality factor in an image processing package e.g.
Open image1.jpg
Set quality factor to 50
Save as image2.jpg
This is to reduce the size of the jpg files in my application.
Does anyone know if there are .NET libraries for this or any good commercial toolkits.
|
|
|
|
|
<br />
System.Drawing.Imaging.EncoderParameters encParams = new System.Drawing.Imaging.EncoderParameters();<br />
encParams.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, Quality);<br />
MemoryStream ms = new MemoryStream();<br />
_reformattedImage.Save(ms, System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders()[1], encParams);<br />
_reformattedImage = Image.FromStream(ms);
That's raw code straight out of an app i've got infront of me it's got the quality methods you'll need though. Quality is the parameter from 1 to 100 that sets the quality level
Things like Bitmap should have load and save methods on them (you can load jpegs into bitmap objects).
HTH
Russ
|
|
|
|
|
Thanks Russell. For completeness my final solution was:
private ImageCodecInfo GetEncoderInfo(String mimeType)<br />
{<br />
int j;<br />
ImageCodecInfo[] encoders;<br />
encoders = ImageCodecInfo.GetImageEncoders();<br />
for(j = 0; j < encoders.Length; ++j)<br />
{<br />
if(encoders[j].MimeType == mimeType)<br />
return encoders[j];<br />
} <br />
return null;<br />
}<br />
<br />
Image image = Image.FromFile(sourceFile);<br />
<br />
string mimeType = "image/jpeg";<br />
ImageCodecInfo codecInfo = GetEncoderInfo(mimeType);<br />
if (codecInfo == null)<br />
raise error;<br />
<br />
Encoder qualityEncoder = Encoder.Quality;<br />
EncoderParameter ratio = new EncoderParameter(qualityEncoder, 40L);<br />
EncoderParameters encoderParams = new EncoderParameters(1);<br />
encoderParams.Param[0] = ratio;<br />
<br />
image.Save(destFile, codecInfo, encoderParams);<br />
image.Dispose();<br />
|
|
|
|
|
I am working on a project in c# windows forms. The app requires to read xml file which contains the information about control to draw on the form.
below Sample xml file information:
<control type="Label" id="label1" width="23" height="23" xPos="117" yPos="100" />
<control type="TextBox" id="textBox1" multiline="false" width="143" height="23" xPos="117" yPos="50" />
<control type="Button" id="button1" width="23" height="23" xPos="100" yPos="100" />
The scenario is if I add a new control to the xml file and re-run the windows application it should be able to draw the new control with other controls in the xmlfile on the windows form.
Please help
MSx86
|
|
|
|
|
Use reflection. type tells you what control to instantiate. the remainder of the attributes tell you what properties to set. Then all you do is add the control to the Controls collection on the form.
|
|
|
|
|
Thanks a million.
Can you give me a sample? I am new to it. I didn't understand what you mean.
|
|
|
|
|
Looks like you are reinventing the wheel a bit here. Take a look at what Marc Clifton[^]has done with MyXaml[^] and MicroXaml.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Good point but I cannot use XAML. I just need to populate some basic controls.
|
|
|
|
|
A couple of points. The first part is that Marcs implementation isn't XAML - it's his own version. Point 2 - Marc has solved the problems that you are trying to solve, so learn from him. He's one of the best on CP, and if you think you want to do something then chances are, Marc's already done it.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Thank you, I will take a look at it. Any particulator article you can point me on his website.
|
|
|
|
|
Try this: http://www.marcclifton.com/tabid/67/Default.aspx[^]
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi, I want to clip a specific portion of the bitmap, and want to display that clip at certain point on the form. Can any one help me? I am looking for a c#.net solution.
Thank you
|
|
|
|
|
Save the image in a buffer and then selecting the particular part using scan and bmdata u can make a region of the required portion then paint that region on the form...... Im doing the same type of thing just a rough idea abt it..... Im also searching out abt it........ Update it if u get the problem solve
BEST OF LUCK
|
|
|
|
|
Hi, Did try Clipping in c#.net library as
Graphics g= CreateGraphics();
Rectangle clip_rect=new Rectangle(0,0,100,100);
g.Clip=new Region(clip_rect);
it can work?
|
|
|
|
|
No I dont think soo!!!!! It can only clip the image to be drawn in a particular rectangle but u cant select a particular portion in the image for doin soo u have to select pixels frm the image...using Bitmapdata and locking the bitmap.......Ya do read christian Gauss image processing articles U ll get to know lot abt image processing.... BEST OF LUCK
|
|
|
|