|
Try handling the main form's Activated event and activating the status form instead.
Alternatively, adjust your design so if the user's supposed to be able to keep editing on the main form, a summary of the status is available on that form (status line? a panel that appears like Visual Studio's error pane?).
|
|
|
|
|
Hi,
From your posting I think that you want to show the main form in taskbar and not the status form when it displayed. To solve this issue try setting parent property of the status form.
Hope this helps.
Nitheesh George
http://www.simpletools.co.in
|
|
|
|
|
How can I do that?
That's how I currently control my forms.
frmMain- Form:
- Clicked event on a button creates object of an action class
clsUsage _clsUsage = new clsUsage();<br />
_clsUsage.CalcUsage();<br />
CalcUsage calls and closes the status form
frmStatus _frmStatus = new frmStatus();<br />
_frmStatus.Show();<br />
_frmStatus.Close();
|
|
|
|
|
Hi
try the following.
frmStatus _frmStatus = new frmStatus();
frmStatus.parent = this;
frmStatus.showInTaskbar = false;
_frmStatus.Show();
//doing some operations and modifying attributes to controls of frmStatus form
_frmStatus.Close();
hope this helps
Nitheesh George
http://www.simpletools.co.in
|
|
|
|
|
Not so easy because the call of the form is in my action class.
Tried the following.
private Form parentForm;<br />
<br />
public Form ParentForm<br />
{<br />
get { return parentForm; }<br />
set { parentForm = value; }<br />
}<br />
<br />
_clsUsage.ParentForm = this;<br />
<br />
_frmStatus.Parent = ParentForm;
But this creates an ArgumentException.
|
|
|
|
|
I am using following code:
dgTrans.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dgTrans_EditingControlShowing);
private void dgTrans_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox combo = e.Control as ComboBox;
System.Diagnostics.Debug.WriteLine(dgTrans.CurrentCell.ColumnIndex + "EditControlShowing");
if (combo != null)
{
combo.SelectedIndexChanged -= new EventHandler(dgcboDocNo_SelectedIndexChanged);
combo.SelectedIndexChanged += new EventHandler(dgcboDocNo_SelectedIndexChanged);
}
}
private void dgcboDocNo_SelectedIndexChanged(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine(dgTrans.CurrentCell.ColumnIndex + "SelectedIndexChanged");
string docno = ((ComboBox)sender).Text.ToString();
DataRow[] dr = myDs.Tables["DetailDocRegister"].Select("DocNo = '" + docno + "'");
int y = dgTrans.CurrentCellAddress.Y;
dgTrans.Rows[y].Cells[1].Value = dr[0]["DocTitle"];
}
But it not work properly. the first column is combobox. second is textbox, which will show the value according to what selected in combobox column. the first time select one item in combobox, it is ok. when you continue select items in second row. one error comes out.But if you select combobox column, then click another column, then select items in another row, it works.
how to solve this problem? thanks for your help.
|
|
|
|
|
In your SelectedIndexchanged event handler you appear to be trying to get the value for the text column from the underlying DataSet. When the SelectedIndexChanged event fires the new value has not yet been propagated to the DataSet. This doesn't happen until later. Definitely after the EndEdit for the combo column fires but exactly when depends on how your dgv is set up.
This may be the cause of your problems. It is difficult to be precise as you do not state clearly what 'one error comes out' means.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
|
|
|
|
|
thanks for your reply, henry.
The error happens here: dgTrans.Rows[y].Cells[1].Value = dr[0]["DocTitle"]; with description "Index was outside the bounds of the array". It means no result in datarow array dr[]. how to do nothing if no result in dr[]?
|
|
|
|
|
OK.
Simply test for a valid dr before trying to do anything with it.
private void dgcboDocNo_SelectedIndexChanged(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine(dataGridView1.CurrentCell.ColumnIndex + "SelectedIndexChanged");
string docno = ((DataGridViewComboBoxEditingControl)sender).Text.ToString();
DataRow[] dr = myDs.Tables["DetailDocRegister"].Select("DocNo = '" + docno + "'");
if (dr.Length > 0)
{
int y = dataGridView1.CurrentCellAddress.Y;
dataGridView1.Rows[y].Cells[1].Value = dr[0]["DocTitle"];
}
}
Note that I have also changed your reference to string docno = ((ComboBox)sender).Text.ToString(); this is because the DataGridViewComboBoxEditingControl has properties and methods that a plain old ComboBox doesn't. One day you might need to use them so it's a good idea to get into the habit of using the proper control now. You should also do this in your EditingControlShowing handler:
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
DataGridViewComboBoxEditingControl combo = e.Control as DataGridViewComboBoxEditingControl;
System.Diagnostics.Debug.WriteLine(dataGridView1.CurrentCell.ColumnIndex + "EditControlShowing");
if (combo != null)
{
combo.SelectedIndexChanged -= new EventHandler(dgcboDocNo_SelectedIndexChanged);
combo.SelectedIndexChanged += new EventHandler(dgcboDocNo_SelectedIndexChanged);
}
}
Hope this helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
|
|
|
|
|
It really works. thank you very much, Henry.
|
|
|
|
|
Incidentally, if you are doing a fair amount of work with the DGV you might find the following links of interest. They are for the same thing but one is in *.doc format and the other is a *.pdf.
DataGridview FAQ.doc[^]
DataGridView FAQ.pdf[^]
Sample code is available at Sample Code[^]
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
|
|
|
|
|
How to save a folder in one location to save in a different location using c# ?
|
|
|
|
|
|
If you want to copy try
public static void CopyDirectory(string source, string destination, bool overwrite)
{
if (!Directory.Exists(destination))
Directory.CreateDirectory(destination);
DirectoryInfo dirInfo = new DirectoryInfo(source);
foreach (FileInfo fileInfo in dirInfo.GetFiles())
fileInfo.CopyTo(Path.Combine(destination, fileInfo.Name), overwrite);
foreach (DirectoryInfo subDirectoryInfo in dirInfo.GetDirectories())
CopyDirectory(subDirectoryInfo.FullName, Path.Combine(destination, subDirectoryInfo.Name), overwrite);
}
Snippet found here
"You get that on the big jobs."
|
|
|
|
|
Hi.
I know how to edit these files. I've lost a number of sources so I had to rebuild. But, I have one app that I cannot replace the resource. App is C# of course.
From Reflector: http://www.imagebam.com/image/6001d3124889081[^]
There are .baml files and even some pngs and gifs. I managed to replace pngs before but here I cannot. Why? Is it because of PinnedMemory thing?
Any help would be appreciated.
|
|
|
|
|
I had developed an application which is a desktop application and DB is Online.
What i need is a Message popup to all the clients whenever i upload a new version on net.
(Installer is online)
Source used - C#, SQL 2008, Crystal Report 11, flash
I have no idea how to start this activity.
Please help
|
|
|
|
|
|
Or have a newsletter to which people can subscribe.
|
|
|
|
|
I want to know how to define property?
|
|
|
|
|
|
|
Hi,
To add a property say Name do the following in your class.
private string _name;
public string Name
{
get{ return _name;}
set {_name = value;}
}
hope this helps.
Nitheesh George
http://www.simpletools.co.in
|
|
|
|
|
It does, but just as a note. In an instance like this it is cleaner to use the auto-property. public string name { get; set; } with no private member defined. (Your answer is still correct, of course)
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
I am writing a socket server and I have some trouble which I did expose through the program below.
If your run this program (this is a console program).
You'll find it open a web browser on a local address and shows 256 small pictures.
For the purpose of this test the pictures are actually quite large but are shown in small.
This is the complete C# 4.0 source, I encourage you to try it.
It really render really fast considering the time I have put into this.
But if you refresh your page you'll see that some of the pictures do not appear properly.
Anyone knows the reason for this.
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace MiniHttpServer
{
class Program
{
static void Main(string[] args)
{
HttpServer.Test();
}
class HttpServer
{
internal static Byte[] mIndex;
internal static Byte[] mPic;
Socket mMainSocket;
bool mUseHttp11;
static HttpServer()
{
mIndex = GetIndex();
mPic = GetCirclePicture();
}
public static void Test()
{
var httpServer = new HttpServer();
httpServer.StartServer(port: 3005, nbListeners: 4, useHttp11: true);
Process.Start("http://localhost:3005/");
Console.WriteLine("Press a key to exit");
Console.ReadKey(intercept: true);
httpServer.Stop();
}
private static Byte[] GetIndex()
{
StringBuilder html = new StringBuilder();
html.AppendLine("<html><body>");
html.AppendLine("<h1>Pics</h1>");
int k = 0;
for (int j = 0; j < 16; j++)
{
for (int i = 0; i < 16; i++)
{
html.AppendLine("<img width='16' height='16' src='p" + (k++) + ".png'>");
}
html.AppendLine("<br/>");
}
return Encoding.UTF8.GetBytes(html.ToString());
}
private static Byte[] GetCirclePicture()
{
var bmp = new Bitmap(256, 256);
using (var g = Graphics.FromImage(bmp))
{
for (int i = 0; i < 128; i++)
{
g.FillEllipse(new SolidBrush(Color.FromArgb(i, i, 255)), i, i, 255 - 2 * i, 255 - 2 * i);
}
}
var mem = new MemoryStream();
bmp.Save(mem, ImageFormat.Png);
return mem.ToArray();
}
public void StartServer(int port, int nbListeners, bool useHttp11)
{
mUseHttp11 = useHttp11;
var webAddress = new IPEndPoint(IPAddress.Loopback, port);
try
{
mMainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
mMainSocket.Bind(webAddress);
mMainSocket.Listen(255);
for (int i = 0; i < nbListeners; i++)
{
CreateListener(i);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
private void CreateListener(int l)
{
var newTask = Task.Factory.StartNew(delegate
{
var requestSocket = mMainSocket.Accept();
Console.WriteLine("L{0} is Accepted", l);
ProcessRequest(requestSocket, l);
Console.WriteLine("L{0} is dying gracefully", l);
}).ContinueWith(delegate
{
if (mMainSocket.IsBound)
{
Console.WriteLine("L{0} is really dead and is trying to resurrect", l);
CreateListener(l);
}
else
{
Console.WriteLine("L{0} is really dead and burried", l);
}
});
}
private void ProcessRequest(Socket requestSocket, int l)
{
try
{
const int BUFFER_SIZE = 4096;
var requestBuffer = new Byte[BUFFER_SIZE];
int requestPos = 0;
int requestNo = 0;
while (requestPos < BUFFER_SIZE)
{
SocketError socketError;
var read = requestSocket.Receive(requestBuffer, requestPos, requestBuffer.Length - requestPos, SocketFlags.None, out socketError);
if (socketError == SocketError.TimedOut)
{
continue;
}
if (read == 0) continue;
var requestString = Encoding.ASCII.GetString(requestBuffer, 0, read);
var sr = new StringReader(requestString);
var line = sr.ReadLine();
var request = line;
while (line != null && line.Length > 0)
{
line = sr.ReadLine();
}
if ((line = sr.ReadToEnd()) != null && line.Length > 0)
{
Console.WriteLine("Lost:" + line);
}
int len = requestPos + read;
int pos = IndexOfCrLfCrLf(requestBuffer, len);
if (pos >= 0)
{
if (pos == 0)
break;
requestNo++;
Console.WriteLine("{0} is processing request #{1}", l, requestNo);
requestPos = 0;
string response = "Hello";
string contentType = "text/plain";
Byte[] responseArray = null;
if (requestString.StartsWith("GET / "))
{
contentType = "text/html";
responseArray = mIndex;
}
else if (requestString.IndexOf(".png") >= 0)
{
contentType = "image/png";
responseArray = mPic;
}
if (responseArray == null) responseArray = Encoding.UTF8.GetBytes(response);
string header =
"HTTP/1." + (mUseHttp11 ? '1' : '0') + " 200 OK\r\n"
+ "Content-Length: " + responseArray.Length + "\r\n"
+ (mUseHttp11 ? ("Content-Type: " + contentType + "\r\n") : "")
+ "\r\n";
byte[] headerArray = Encoding.UTF8.GetBytes(header);
requestSocket.Send(headerArray, headerArray.Length, SocketFlags.None);
requestSocket.Send(responseArray, responseArray.Length, SocketFlags.None);
if (mUseHttp11 == false)
{
requestSocket.Close();
break;
}
}
else requestPos = len;
}
Console.WriteLine("Request complete");
}
catch (Exception ex)
{
Console.WriteLine("Exception " + ex.Message);
}
}
private void Nop()
{
}
public void Stop()
{
mMainSocket.Close();
}
static int IndexOfCrLfCrLf(byte[] requestBuffer, int len)
{
for (int i = 0; i <= (len - 4); i++)
{
if (requestBuffer[i] == '\r'
&& requestBuffer[i + 1] == '\n'
&& requestBuffer[i + 2] == '\r'
&& requestBuffer[i + 3] == '\n')
{
return i;
}
}
return -1;
}
}
}
}
|
|
|
|
|
The Shadow knows...
|
|
|
|