|
I'd recommend to encode it in Base64. That way you can even throw (binary) pictures in there.
|
|
|
|
|
Surprisingly there is a standard for CSV.
Text Fields are surrounding by "". " escapes ", pretty simple.
|
|
|
|
|
How to optimise code every time needs to bind the grid
|
|
|
|
|
Your best of showing what code you think need optimization and others will let you know of potential improvements.
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
sujeet321 wrote: How to optimise code
You do this by appying your VAST knowledge and experience in programming.
|
|
|
|
|
Look at the query first. Make sure you only pick up what you need to display.
Your gridview will be faster automatically.
|
|
|
|
|
In a gridview, how to change the background color of a selected row, on click of a cell in datagridview. Thanks in advance
modified 1-Feb-13 4:11am.
|
|
|
|
|
Handle the CellClick event:
private void myDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
DataGridView dgv = sender as DataGridView;
if (dgv != null)
{
dgv.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red;
}
}
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
Thanks for your reply.
The code which you sent changing the back color of a row, wherever I click in the gridview.
So entire grid resulted in red background color
My issue is to change the selected background color. To describe more, If I click on first row, background color should change to Dark Gray color. after that, if I click on second row, first row should get reverted to previous color and second row background color should be in darkgray color.
|
|
|
|
|
Do you expect me to do everything for you?
Keep a "I changed this" row index, and change it back. Then set the new row, and save the index. It's not exactly rocket science...
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
Strange how we both chose Red.
|
|
|
|
|
Easy to type!
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
Set your row default selection colour in your form design, or add the following during initialisation:
gridView.Rows[e.RowIndex].DefaultCellStyle.SelectionBackColor = Color.Red;
And add something similar to the following to your cell click event:
gridView.Rows[e.RowIndex].Selected = true;
|
|
|
|
|
In CellClick event, below statement worked. Thank you.
dgvTestCaseDetails.Rows[e.RowIndex].Selected = true;
|
|
|
|
|
Hi friends,
I am trying to write a log file by using log4net, which should write all log events in default event log. Please help me to do it.
Thanks and Regards
Venkat
|
|
|
|
|
|
|
The same as usually. The Dispose method is called on the objects named in the Using statement.
ThreadAbort raises an exception in the specified thread. It's not an immediate termination of the thread.
|
|
|
|
|
Dave Kreskowiak wrote: The same as usually.
I don't like "Usually" ...
I read from somewhere that [^]lock(x) statement is syntactic sugar, that JIT compiler will autogenerate the following:
<br />
Monitor.Enter(o);<br />
S0;<br />
try {<br />
S1;<br />
} finally {<br />
Monitor.Exit(o);<br />
}<br />
However, for some compiler architecture, your code will not cleanup properly if Thread.Abort called at point "S0" above before the generated try block, thus Monitor.Exit will not be exited.
But hold - I just found out the answer - I missed the update from the referenced post which says M$ corrected the problem:
<br />
Update 4/17/08: This was indeed fixed for the X64 JIT in Visual Studio 2008. Note that when compiling C# code targeting both X86 and X64, if you do not use the /o+ switch, this problem can still occur due to extra explicit NOPs inserted before the try.<br />
<br />
The framework implements a method Monitor.ReliableEnter, by the way, that could be used to avoid orphaning locks in the face of thread aborts, but it's internal to mscorlib.dll. It sets an out parameter within a region of code that cannot be interrupted by a thread abort, which the caller can then check inside the finally block. The acquisition then gets moved inside so that, if the CALL is reached, the finally block is guaranteed to always run. You'd then write this instead:<br />
<br />
bool taken;<br />
try {<br />
Monitor.ReliableEnter(o, out taken);<br />
S1;<br />
} finally {<br />
if (taken)<br />
Monitor.Exit(o);<br />
}<br />
Problem solved!
dev
modified 1-Feb-13 0:09am.
|
|
|
|
|
devvvy wrote: I don't like "Usually" ...
Mistyped. It should have been "usual".
|
|
|
|
|
no worries, anyway, I posted the link to the update where it says M$ fixes that issue with JIT so lock/using are both safe to use on a thread function (in context of Thread.Abort)
problem solved.
dev
|
|
|
|
|
Looks like M$ fixed that issue with releasing lock - I tested on Windows 8 64 bit zero miss.
Looks like we can conclude:
a. using/lock statements both compatible with Thread.Abort that both would release the resource before thread is dead.
b. Thread.Abort is no longer Evil (If all resources created on the Thread - user remember to release in catch or finally block)
<br />
class Program<br />
{<br />
static object obj = new object();<br />
<br />
static void Main(string[] args)<br />
{ <br />
try<br />
{<br />
for (int i = 0; i < 1000; i++)<br />
{<br />
Thread thRun = new Thread(new ThreadStart(ThreadFunc));<br />
thRun.Start();<br />
<br />
Thread.Sleep(300);<br />
<br />
thRun.Abort();<br />
<br />
lock (obj)
{<br />
Console.WriteLine(i + ": Done locking obj from main");<br />
}<br />
}<br />
<br />
Console.WriteLine("Hit any key to exit");<br />
Console.ReadLine();<br />
}<br />
catch (Exception Ex)<br />
{<br />
Console.WriteLine("Error in main: " + Ex.Message);<br />
}<br />
<br />
return;<br />
}<br />
<br />
static void ThreadFunc()<br />
{<br />
lock (obj)<br />
{<br />
using (DataContainer SomeContainer = new DataContainer())<br />
{<br />
Console.WriteLine("ThreadFunc lock begins");<br />
Thread.Sleep(1000 * 10);<br />
}<br />
}<br />
Console.WriteLine("ThreadFunc lock released");<br />
<br />
return;<br />
}<br />
}<br />
<br />
class DataContainer : IDisposable<br />
{<br />
protected bool m_isDisposed = false;<br />
<br />
public void Dispose()<br />
{<br />
Dispose(true);<br />
GC.SuppressFinalize(this);<br />
}<br />
<br />
~DataContainer()<br />
{
Dispose(false);<br />
}<br />
<br />
protected virtual void Dispose(bool disposing)<br />
{<br />
Console.WriteLine("DataContainer.Dispose: " + disposing);<br />
<br />
if (m_isDisposed)<br />
return;<br />
<br />
if (disposing)<br />
{<br />
}<br />
m_isDisposed = true;<br />
}<br />
}<br />
dev
|
|
|
|
|
A few C# 2008 and C# 2010 the applications were written as console applications. However now I want the programs to compile as windows applications instead. The problem is when I checkout the code from version control software, the default compile option for these programs is as a console application.
Thus is there a way in visual studio 2008 and/or visual studio 2010 to set the default compile option for these programs to be windows applications? If so, can you tell me how to accomplish this goal?
|
|
|
|
|
Do you want to change the app to a windows service or to a winforms app. Both will need some modifications from a console app.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
There is nothing that will automatically convert those to WinForms apps. You WILL have to recode the apps at least minimally to accomplish this conversion. Since we can't see the source code, it's impossible to tell you exactly what you have to do or how much work it's going to be. It really depends on the quality of the original coding job.
|
|
|
|