|
I'm using the following solution as my DataGridView Printer
Printing a DataGridView on DotNet Framework[^]
I'm attempting to modify it with no current luck.
When I print out my results the cell's BackColor always seems to be grey when the cell's in my DataGridView are a combination of different colors. These aren't set per row or per column, they are per cell.
I'm looking at GridDrawer.cs and i'm guessing this is because of the Method DrawRows and the line
g.FillRectangle(new SolidBrush(row.BackColor()), RowBounds);
I changed it and verified that it does change the row's back color.
How can I modify this so that each cell's BackColor represents the correct color from the DataGridView?
Or if there is another solution that already does this per cell not per row formatting that would be great also.
Thanks
|
|
|
|
|
Don't ask this here - if you look at the article, there is a "messages" section at the bottom, which allows you to talk to the author directly. Any comment you post there sends an email to the original author of the article, so he can read it. Posting here relies on him "dropping by" and realizing it is for him!
This message is manufactured from fully recyclable noughts and ones. To recycle this message, please separate into two tidy piles, and take them to your nearest local recycling centre.
Please note that in some areas noughts are always replaced with zeros by law, and many facilities cannot recycle zeroes - in this case, please bury them in your back garden and water frequently.
|
|
|
|
|
Hi,
My requirement is to read a XML string, Manipulate and store it in MS SQL Server.
XML:
<?xml version="1.0" encoding="UTF-8" ?>
<Data>
<Table1>
<Col1>Value1</Col1>
<Col2>Value2</Col2>
<Col3>Value3</Col3>
</Table1>
<Table1>
<Col1>Value1a</Col1>
<Col2>Value2a</Col2>
<Col3>Value3a</Col3>
</Table1>
...
...
...
...
</Data>
its available in string
string sXML = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><Data><Table><Col1>Value1</Col1><Col2>Value2</Col2><Col3>Value3</Col3></Table><Table><Col1>Value1a</Col1><Col2>Value2a</Col2><Col3>Value3a</Col3></Table></Data>"
MS SQL Server table structure and xml mapping
MyTable - XML
Column1->Col1
Column2->Col2
Column3->Col3
Column4->Col1+Col2
Column5->Col3+200
Column6-> {current system date}
Column-> {Default constraint stores '0' always}
Number of rows inserted will be max of 100 rows at a time
current clients accessing this app and passing XML would be around 20
Frequency of calling is 1 min
I use .NET 4.0, C# and MS SQL Server 2008
My Approach is read, xml file, manipulate it, store in dataset/datatable and do the bulk copy.
My Question is :
1. In this approach, How to manipulate and store it in dataset/datatable
1. Is there any better way to do it?
Thank you.
|
|
|
|
|
No need to over think / over engineer things.
1) load string into XML DOM
2) loop through table1's with xPath
3) bulk insert into SQL
If you want to be somewhat tricky, you only really need to insert the first 3 columns. The other 4 can be auto computed.
|
|
|
|
|
Hello Friends,
i Need API which will convert MS-Office files to PDF files
any help ?
|
|
|
|
|
|
hey
How can I have it so someone can click on a "Click here to Upload" button, and then select a file off their computer, (And preferably I'd like to be able to limit what kinda files they could upload to just .rar files) once they upload the file, an admin on the website can view the uploaded file, and click an "approve or Deny" button, and be able to download the file.
|
|
|
|
|
Ayesha Atif wrote: <layer>How can I have it so someone can click on a "Click here to Upload" button, and then select a file off their computer, (And preferably I'd like to be able to limit what kinda files they could upload to just .rar files) There's an option on the filedialog that let's one specify a filter. The same thing that causes users to rename the file-extension when sending a zip-file using GMail.
Ayesha Atif wrote: once they upload the file, an admin on the website can view the uploaded file, and click an "approve or Deny" button, and be able to download the file. Uploading a file, putting it somewhere on the server, have "someone" click a button - those are basic operations. Did you look for an example?
We can help with specific coding-questions; as is, this sounds like a request for an ASP.NET application.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You can also sometimes detect the type of file beyond the standard ext by readings it into binary and checking the first couple of bytes to see if its a zip file, mp3.. etc..
Its a method to prevent people form uploading say exe with a .jpg extension..
I have done it with Mp3's and it worked pretty good.
=)
|
|
|
|
|
Hi,
I am working on a project about watermarking, so in part of my project I need to know some information and structure about a JPEG file header.
I searched many sites and red some articles but they were not useful... by the way I decide to ask from you.
In my project I'm trying to read inside a jpeg file by Buffer Streaming and I need to know from where through where is about what (seems complicated!! ).
Maybe if I know the header structure of a JPEG file, I will solve my problem.
Thanks
|
|
|
|
|
You need to study the JPEG standard - available online here[^]
First, read the paper by Gregory Wallace available here[^].
modified 28-Aug-13 6:37am.
|
|
|
|
|
Dear Amarnarh, Thank u...
I have red some books like:
* JPEG2000 Image Compression Fundamentals, Standards and Practice(2002)
* JPEG2000 Standard for Image Compression Concepts Algorithms and VLSI Architectures
But my question exactly is about offset of information included in JPEG header.
Thanks again
|
|
|
|
|
What's so hard about typing "jpeg file format" into Google??
|
|
|
|
|
...?
I am talking about data structure of jpeg files.
|
|
|
|
|
Yeah, and ...?
You we're given links to the internals of JPEG, how it works, and told how to find the file format. There is nothing else in this process.
You can only either work with the data as it is in the file or with the data as it is represented in memory, which, by the way, in GDI is NOT in a JPEG format. You've been given both.
|
|
|
|
|
Hi Guys.
I am having a situation here, i want to read a dynamically textarea content,
String CommentOut = null;
for (int intX = 0; intX < dt.Rows.Count; intX++ )
{
CommentOut += "<div class='commentBox'><table><tr><th>" + dt.Rows[intX][2].ToString() + " on:" + dt.Rows[intX][1];
CommentOut += "</th></tr><tr><td bgcolor='#f5f1f1'>" + dt.Rows[intX][4].ToString() + "</td></tr><tr><td class='commentBoxIns'>";
Quir = "Select Username_ as 'Posted By', comment_ as 'Comment', Date_ as 'date' ";
Quir += " From CommentsTBL_ where CommentID_ = '" + dt.Rows[intX][0].ToString() + "'";
SqlCommand Sqlcom2 = new SqlCommand(Quir, Con);
SqlDataAdapter Adapt2 = new SqlDataAdapter(Sqlcom2);
DataTable dt2 = new DataTable();
Adapt2.Fill(dt2);
for(int intY=0; intY<dt2.Rows.Count; intY++){
CommentOut += "<table width='70%' align='right'></tr><th>" + dt2.Rows[intY][0].ToString() + " on:" + dt2.Rows[intY][2].ToString();
CommentOut += "</th></tr><tr/><td>" + dt2.Rows[intY][1].ToString();
CommentOut+= "</td></tr></table>";
}
Adapt2.Dispose();
dt2.Dispose();
Sqlcom2.Dispose();
CommentOut += "</td></tr><tr><td><textarea id='comment" + intX + "' name='comment" + intX + "' rows='5' cols='20' style='width:97%;' runat='server'>type your comment here</textarea>";
CommentOut += "</td></tr><tr class='commentBoxCom'><td><a href=?ID1=" + dt.Rows[intX][0].ToString() + "&ID2=comment" + intX + ">Comment</a>";
CommentOut += "</td></tr><tr><td>";
CommentOut += "</table> </div><br/>";
}
this.LitCont.Text = CommentOut;
|
|
|
|
|
You'll need to be more specific. Please edit your question and tell us what the specific issue is. What have you tried that isn't working? Is it throwing an error? If so, tell us what it is. Some general information about what you are trying to do would be helpful and an idea of how this fits into the bigger picture.
Your post, as-is, is way too generic. You have dumped your car at the mechanic and said, "something is wrong." Imagine for a moment that we have no idea what you are doing and pretend that we need to be told all of the information you have about the problem.
|
|
|
|
|
|
OK... you explained your code and provided some additional code but you still haven't told us what the problem is. What are you trying to do? What is the problem? What have you tried that isn't working?
Unless you can define the desired behavior and how your code is deviating from that, we can't help you. Nobody can look through what you have posted to find an error that you haven't defined.
|
|
|
|
|
Ok i am sorry i am having dificulties in explaining myself, but the idea i had in mind is to create a textarea using a c# code, and i managed to do that well but i can not figure out any other way of reading from the text area that i have created, and when i am trying to read from it i get blank results(as if it is null)
|
|
|
|
|
I'm still not completely sure what you are trying to do but I'm guessing that you are rendering a table of results and are looking for the comments that a user puts into the page. Am I on the right track here?
If this is the case, you are going about it the wrong way. You are generating an HTML page with your code. Once you pass that on, it is rendered in a browser on the client machine. Your code has no direct link to that rendered page. The same as if you rendered the page in ASP on a server and sent it to the client. The server no longer has any reference to that document once it is transmitted to the client end.
To get back what a user enters into a web page, the document needs to be posted back to the server or you need to do some sort of AJAX call so the data is sent back. Both of these are client side operations. If you are rendering the page inside of a browser control, you might be able to access the DOM in that control and get at the data.
I'm not an expert in client side web development. You might be better off asking in the ASP forum.
However, if you are doing this in a C# winforms or WPF app, I would ask why you are rendering table-type data in a web page rather than using a data grid or something like that?
|
|
|
|
|
Hi Jason, thanx alot for taking your precious time and try to listen and for helping me out,
Your guessing was correct, okay I heard you there when you suggested that I should look into Ajax to make that happen,
The reason for me to use the table instead of the gridview is pretty much not that necessary because all I wanted to use something different than I can actually control the look and feel of the interface, I also felt like I have relied too much on the gridviews... the bottom line is, I wanted something different
|
|
|
|
|
Oddly is that when I send the 9 character length of a string (i.e. 123A45678), my serial port dataReceived event recieves the message but it reads as:
123A4567
8
Unsure on how to get the whole string as was sent by the other com port?
here's my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using RS232;
namespace RemoteCFG
{
public class RemoteConfiguration
{
SerialPort serialPort;
RS232Comm rs232Comm = new RS232Comm();
Object lockingObj = new object();
public RemoteConfiguration()
{
}
public string strMessage { get; set; }
public string cfgNumber { get; set; }
public string vloValue { get; set; }
public string atcValue { get; set; }
public List<string> EnumerateComPorts()
{
return rs232Comm.GetAvailableComPorts();
}
public int OpenPort(string comPort)
{
serialPort = rs232Comm.OpenPort(comPort);
serialPort.DataReceived +=new SerialDataReceivedEventHandler(serialPort_DataReceived);
if (serialPort != null)
return 1;
else
return 0;
}
public int ClosePort()
{
try
{
serialPort.Close();
return 1;
}
catch (Exception ex)
{
return 0;
}
}
void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string inData = sp.ReadExisting().Trim();
strMessage = inData;
switch (inData)
{
case "PLC": SendMsg("OK"); break;
case "CFG": ValidateCFG(); break;
case "OFF": serialPort.Close(); break;
case "VLO": GetVLO(); break;
case "ATC": GetATC(); break;
default: System.Diagnostics.Debug.WriteLine(strMessage); break;
}
}
private void GetATC()
{
if (atcValue != null && atcValue != string.Empty)
{
int value = 0;
if (int.TryParse(atcValue, out value))
{
if (value >= 0 || value <= 99)
{
SendMsg(atcValue);
}
}
}
}
private void GetVLO()
{
if (vloValue != null && vloValue != string.Empty)
{
int value = 0;
if (int.TryParse(vloValue, out value))
{
if (value >= 60 || value <= 120)
{
SendMsg(vloValue);
}
}
}
}
private void ValidateCFG()
{
if (cfgNumber != null && cfgNumber != null && cfgNumber != string.Empty)
{
if (cfgNumber.Length == 9)
{
try
{
int Num = 0;
if (int.TryParse(cfgNumber.Substring(0, 3), out Num))
{
int errorCounter = System.Text.RegularExpressions.Regex.Matches(cfgNumber.Substring(3, 1), @"[a-zA-Z]").Count;
if (errorCounter == 1)
{
if (int.TryParse(cfgNumber.Substring(4), out Num))
SendMsg(cfgNumber);
}
}
}
catch
{
}
}
}
}
public int GetCFG(ref string configNumber)
{
int status = 0;
try
{
SendMsg("CFG");
configNumber = strMessage;
}
catch
{
}
return status;
}
int GetDynData(string[] dynamicData)
{
int status = 0;
return status;
}
public int SendMsg(string msg)
{
int status = 0;
serialPort.Write(msg + "\r");
return status;
}
}
}
The serial port is initilized as:
serialPort = new SerialPort(comPortName, 9600, Parity.Even, 7, StopBits.One);
serialPort.Handshake = Handshake.XOnXOff;
|
|
|
|
|
You serial port is set at 9600 baud - this is not a fast speed, certainly not in modern terms.
9600 baud means 9,600 bits per second, so with 1 start bit, one stop bit, even parity and 7 bits per character that's a maximum data transfer rate of 960 characters per second.
You SerialPort.DataRecieved event does not fire when the final character is received, it fires when the first character is received. And the second, and the third....
So when you read all the data from the serial port buffer, you will get a "random" number of characters, which may - or may not be - the whole message you are looking for.
Instead of your existing code, set up a BackgroundWorker thread which processes input data from the serial port, scans it to find whole messages, and then signals up to the main thread that a whole message is ready. If it gets a "partial message" is stores it, and adds the next data on the end before scanning it again.
This message is manufactured from fully recyclable noughts and ones. To recycle this message, please separate into two tidy piles, and take them to your nearest local recycling centre.
Please note that in some areas noughts are always replaced with zeros by law, and many facilities cannot recycle zeroes - in this case, please bury them in your back garden and water frequently.
|
|
|
|
|
You don't need a background worker and the baud rate has nothing to do with your ability or inability to receive a message.
The SerialPort class already operates on its own thread. The truth is the physical serial port on your PC is implemented with a USART and has no buffer of its own. It can hold a single character. When it receives data, it fires an interrupt. The interrupt handler adds the character to a FIFO buffer and notifies the serial port class attached to that port that a character has been received. That message goes into the message queue and your application will receive it via the DataReceived event when the message pump gets around to sending it to your app.
When you read the data from the serial port class, you empty the FIFO buffer either in one swoop or a character at a time. Interlocks are already built into the serial port class so you don't contend with any characters that may be received at the port while the data is being read by the application. For all intents and purposes, you read a string of characters as they have been received up to that point in time.
What is NOT present is any kind of message framing. And that is where you need to do something. The fact is the DataReceived event could be fired for every character that comes in the serial port. You have to grab those characters, append them to a message string, then determine when the message is complete. It is the same as information coming from the keyboard... the user types a single character at a time. If you are looking for a word, you buffer those characters onto a string until you see a space or a carriage return. Same this with the serial port... just think of it as another keyboard where characters arrive (not full strings!).
So you need to decide what your message delimiter is. Normally, for serial communications, the message is ended with a 13... a carriage return. Since it looks like you might be talking to a PLC for data collection, it may also be a fixed-width situation. In that case you need to test the length of the accumulated string each time DataReceived is called. Either way, you need to look for the delimiter or the length in DataRecevied and THEN process your results once the whole string has been received. Make sense?
Secondly, you are casting the serial port from the event arguments. You shouldn't do that. You already have a reference to the serial port in your class-scoped serialPort object. Use it inside of the event handler.
Usually, inside of this event, you setup a While loop that looks at the character count on the serial port. If it is greater than 0, you pull a single character with ReadChar(), check to see if it is your message delimiter, then tack it onto strMessage if it isn't. If it is your delimiter, you pass the message to the processing function and set strMessage to string.empty when you are done.
Remember that DataRecieved is called on a different thread because it is raised by the serial port class. This means your message processing will take place on the worker thread too. If you want to interact with the UI, you will have to marshal the call over to the UI thread.
HTH!
|
|
|
|
|