|
My application pulls data from a MySQL database and saves it as CSV file.
I have to localize this. the main requirement is that date and number format should be localized while making the CSV file.
for ex in German, the delimiter should be ";" instead of " ," . and numbers should have , in place of decimal(1.23 should be 1, 23) and also the date should be in correct format.
now the data I am pulling could be of any type, string, single, double, how can I know the type of pulled data, and format it for the installed UI culture before saving it to the CSV file.
I know that I can find out the type of the column pulled, and use that, is there a better an efficient way ?
Any ideas ?
Thanks,
Arti
|
|
|
|
|
IMHO the most simple solution will be to write data in binary mode. After that data will be automatically reformatted according to local settings of the target computer while reading.
|
|
|
|
|
I am having a problem I am not sure why is hapening. In the following code, if I put the line with the Clone() method before the this.datagridSplit.Panel2.Controls.Add(dataGrid); it works well but I get the error No parameterless constructor defined for this object in a MissingMethodException. My guess is that is because the object is occupied on another thread but I am not sure. Note that when the dataGrid is added to a control I fire another event that modifies the bound table of the datagrid. What a day!
public void SetFinder(ref ComplexObject finderObject) //Type ComplexObject is a typed dataset
{
finderObject.Read();
complexObject = finderObject;
dataGrid = finderObject.FinderDatagrid;
dataGrid.ColumnHeadersVisible = false;
this.datagridSplit.Panel2.Controls.Add(dataGrid);
emptyDataSet = finderObject.Clone();
emptyDataSet.EnforceConstraints = false;
emptyDataSet.Tables[0].Rows.Add(null, null);
emptyDataSet.AcceptChanges();
emptyDataGrid.DataSource = emptyDataSet.Tables[0];
emptyDataGrid.AllowUserToAddRows = false;
emptyDataGrid.Dock = DockStyle.Fill;
emptyDataGrid.RowHeadersVisible = false;
this.datagridSplit.Panel1.Controls.Add(emptyDataGrid);
this.emptyDataGrid.CellValueChanged += new DataGridViewCellEventHandler(emptyDataGrid_CellValueChanged);
this.emptyDataGrid.CellLeave += new DataGridViewCellEventHandler(emptyDataGrid_CellLeave);
}
|
|
|
|
|
Hi
please help me in this:
I have loaded xml document using following DOM class:
<br />
<br />
XmlDocument xDoc = new XmlDocument();<br />
<br />
xDoc.Load("check.xml");<br />
<br />
Now how can i view this xml file similar to internet explorer display?
Either i should draw Rich Text Box or drop WebControl on my the form? I have added WebControl in toolbox but it is disable there.
please help me.
Thank you.
|
|
|
|
|
You mean the control is disabled in your toolbox ?
Cross my heart, smack me dead...stick a lobster on my head.
|
|
|
|
|
Yes here in mine toolbox
|
|
|
|
|
Is there a way to create a program that will constantly update what programs the current user is using? I tried using GetCurrentProcess, but it gets my window, and not the currently activated window. What I do is, I have a thread that will keep watching the processes, calling the GetCurrentProcess function to constantly update. This thread only activates when the form is "deactivated". The problem is that I just keep getting my app, and not the other processes.
|
|
|
|
|
To get all processes running on the local computer.
Process [] localAll = Process.GetProcesses();
Every running process is a current process. GetCurrentProcess retrieves whatever process the method is being run within. It sounds like what you really want to know is which application currently has the keyboard focus. For that you would use GetForegroundWindow (See: MSDN Forums-- Visual C#-- Visual C# General-- How do I determine which program window is active?[^])
However, if you are interested in currently running processes, you could use WMI to get a list, and notify you whenever a new process is created.
See this article: System.Management Lets You Take Advantage of WMI APIs within Managed Code[^]
using System;
using System.Management;
namespace WorkWithProcesses
{
class Class1
{
static void Main(string[] args)
{
ManagementClass processClass = new ManagementClass
(@"root\cimv2:Win32_Process");
foreach (ManagementObject processInstance in
processClass.GetInstances())
{
Console.WriteLine(processInstance["Caption"].ToString());
}
ManagementEventWatcher watcher = new ManagementEventWatcher (
new WqlEventQuery ("SELECT * FROM __InstanceCreationEvent
WITHIN 1 " +
@"WHERE TargetInstance ISA ""Win32_Process"""));
EventHandler handler = new EventHandler();
watcher.EventArrived += new EventArrivedEventHandler
(handler.Arrived);
watcher.Start();
System.Threading.Thread.Sleep(180000);
watcher.Stop();
Console.WriteLine("Done watching for events");
}
}
public class EventHandler
{
public void Arrived(object sender, EventArrivedEventArgs e)
{
Console.WriteLine("Process created = " +
((ManagementBaseObject)e.NewEvent["TargetInstance"])["Caption"]);
}
}
}
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
I am getting the following error when trying to compile this code:
H:\Grid Project\Alchemi-1.0.4-src\src\Alchemi.ManagerServiceController\ManagerMainForm.cs(61): 'ManagerTemplateForm.components' is inaccessible due to its protection level
Here is the code that I am working with. I have a comment on the line where the error is thrown.
#region Alchemi copyright and license notice
#endregion
using System;
using System.ComponentModel;
using System.Reflection;
using System.ServiceProcess;
using System.Threading;
using System.Windows.Forms;
using Alchemi.Core;
using Alchemi.Core.Manager;
using Alchemi.Manager;
using log4net;
[assembly: log4net.Config.XmlConfigurator(Watch=true)]
namespace Alchemi.ManagerService
{
public class ManagerMainForm : ManagerTemplateForm
{
public const string serviceName = "Alchemi Manager Service";
public ManagerMainForm():base()
{
InitializeComponent();
this.Text = "Alchemi Manager Service Controller";
Logger.LogHandler += new LogEventHandler(LogHandler);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container(); <big></big>
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ManagerMainForm));
this.SuspendLayout();
this.cbIntermediate.CheckedChanged += new System.EventHandler(this.cbIntermediate_CheckedChanged);
this.Name = "ManagerMainForm";
this.Text = "Alchemi Manager";
this.Load += new System.EventHandler(this.ManagerMainForm_Load);
this.ResumeLayout(false);
}
#endregion
private void LogHandler(object sender, LogEventArgs e)
{
ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
switch (e.Level)
{
case LogLevel.Debug:
string message = e.Source + ":" + e.Member + " - " + e.Message;
logger.Debug(message,e.Exception);
break;
case LogLevel.Info:
logger.Info(e.Message);
break;
case LogLevel.Error:
logger.Error(e.Message,e.Exception);
break;
case LogLevel.Warn:
logger.Warn(e.Message, e.Exception);
break;
}
}
private void ManagerMainForm_Load(object sender, EventArgs e)
{
ReadManagerConfig(false);
RefreshUIControls();
btStart.Focus();
}
private void ReadManagerConfig(bool useDefault)
{
ManagerContainer mc = new ManagerContainer();
mc.ReadConfig(useDefault);
Config = mc.Config;
mc = null;
}
private void cbIntermediate_CheckedChanged(object sender, EventArgs e)
{
Config.Intermediate = cbIntermediate.Checked;
_container.Config = Config;
RefreshUIControls();
}
#region Implementation of methods from ManagerTemplateForm
protected override bool Started
{
get
{
bool started = false;
try
{
ServiceController sc = new ServiceController(serviceName);
if (sc.Status == ServiceControllerStatus.Running || sc.Status == ServiceControllerStatus.StartPending)
{
started = true;
}
sc = null;
}
catch (Exception ex)
{
logger.Error("Error trying to determine service status",ex);
}
return started;
}
}
protected override void Exit()
{
this.Close();
Application.Exit();
}
protected override void ResetManager()
{
ReadManagerConfig(true);
RefreshUIControls();
}
protected override void StopManager()
{
if (!Started)
{
Log("The Manager Service is already stopped.");
RefreshUIControls();
return;
}
try
{
statusBar.Text = "Stopping Manager Service...";
Log("Stopping Manager Service...");
btStop.Enabled = false;
ServiceController sc = new ServiceController(serviceName);
if (sc.CanStop)
{
sc.Stop();
sc.WaitForStatus(ServiceControllerStatus.Stopped,new TimeSpan(0,0,28));
Log("Manager Service stopped.");
}
else
{
logger.Debug("Couldnot stop service: CanStop = false");
}
}
catch (TimeoutException)
{
Log("Timeout expired trying to stop Manager Service.");
}
catch (Exception ex)
{
Log("Error stopping ManagerService");
logger.Error(ex.Message, ex);
}
RefreshUIControls();
}
protected override void StartManager()
{
if (Started)
{
Log("Manager Service is already started.");
RefreshUIControls();
return;
}
try
{
btStart.Enabled = false;
btReset.Enabled = false;
btStop.Enabled = false;
statusBar.Text = "Starting Manager Service...";
Log("Attempting to start Manager Service...");
ServiceController sc = new ServiceController(serviceName);
if (sc.Status != ServiceControllerStatus.Running && sc.Status != ServiceControllerStatus.StartPending)
{
Config = GetConfigFromUI();
if (Config!=null)
{
Config.Slz();
}
sc.Start();
sc.WaitForStatus(ServiceControllerStatus.Running,new TimeSpan(0,0,28));
Log("Manager Service started.");
}
}
catch (TimeoutException)
{
Log("Timeout expired trying to start Manager Service.");
}
catch (Exception ex)
{
Log("Error starting ManagerService");
logger.Error("Error starting ManagerService",ex);
StopManager();
}
RefreshUIControls();
}
#endregion
}
}
|
|
|
|
|
there are two possibilities which mean the same...
1. you forgot to specify the protection level of the component field in your managertemplateform which means by default that it is set to private
2. you didn't forget it but specify it to private...
Then if you want it to be not accessible by other class than children of the managertemplateform, you specify the protection level to protected...
if you agree that any classes access to it, choose public.
enjoy the code with you is my priority,
Blaise Braye
|
|
|
|
|
Hi every one
I wanted to know how to select Datagridview certain cell.. and highlight it..
for example.. Cell(ColumnIndex, RowIndex).. and then Highlight the cell...
I wanted also to highlight multiple cells.. and color different cells... I'm stuck with this problem for 2 days already..
some one told me about DataGridViewCell.Selected Property.. but i don't know how to use it to solve my problem
so please I need your help urgently...
I'm really appreciated for any hint..
Thanks in advance..
|
|
|
|
|
have you tried row.Cell[x].Style or row.DefaultCellStyle ?
|
|
|
|
|
First: Thanx for ur reply edboe
Second:
"row.Cell[x].Style" Couldn't find something like that
"row.DefaultCellStyle" didn't find something like that also ... but I found this
"DataGridView.DefaultCellStyle" but don't know who to use it to solve my problem..
the major thing for me is to highlight a certain Cell ... let the coloring of the cell be optional..
do u have or any body have any hints??
Thanks in advance...
|
|
|
|
|
If you do a foreach on the DataGridView rows, you will get an individual row. Then you can check your criteria, and change the colors accordingly.
|
|
|
|
|
Thank you very very much edboe for the great hint
Really appreciated..
best regards
|
|
|
|
|
To color cells individually:
dataGridView1.Rows[0].Cells[1].Style.BackColor=Color.YellowGreen;
dataGridView1.Rows[2].Cells[4].Style.BackColor=Color.AliceBlue;
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
I'm really appreciated EricDV....
Thank you very very much
|
|
|
|
|
hello
i'm trying to bind data from a datatable to a textbox as there is only one value to be displayed.
the compiler says that there is no "DataSource" property for a textbox and neither a "DisplayMember" one as they work with datagrids and listViews.
can anuone tell me the replacement of DataSource and DisplayMember with a textBox.
waiting for ur reply
|
|
|
|
|
For databinding I always use the following code which works fine for me
<br />
textbox.DataBindings.Add("P", Datasource, Field)<br />
where "P" is the property of your textbox you wish to bind on (usually "Text")
Datasource is you datasource, for example, a datatable or dataview...
Fiels is the field in your datasource to bind on. For example the name of a column in your datasource.
|
|
|
|
|
Thank You
Eduard Keilholz
it worked just fine
regards
Saira
|
|
|
|
|
Hi all, I am so hoping that someone can help me out here. I'm writing an application for a terminal[^]. I'm only starting to learn C# and with this terminal and all its sort of a double learning curve for me although I am experienced in C++.
I've had plenty problems which I've managed to iron out one after the other but it seems that I have now reached a dead end where I simply lack the know-how to troubleshoot. When I compile my application it gives no warnings or errors. I can run it on the PC but when I copy it across to the device I get various exceptions. And what really concerns me is that I can't readily reproduce these exceptions. The three exceptions that I mostly get are InvalidProgramException , TypeLoadException and MissingMethodException .
When I comment out lines of code from my application, and these can be real meaningless lines such as MessageBox.Show("1st image loaded"); I get another exception. As I said, these exceptions seem not to be predictable and I never know which one I'm going to get - a bit like a box of chocolate (sorry, bad joke ).
Anyway, I would be very appreciative if someone could give me some advice as to how to get to the bottom of this. I'm getting really desperate.
Some background that might be of use:
The device runs Windows CE 4.2 and .NET CF 1.0
I'm using Visual Studio 2005
When creating the project I've selected Visual C# -> Smart Device -> Pocket PC 2003 -> Device Application (1.0)
This is because there is no option for Windows CE 4.2 (only 5.0) and I need to target the CF 1.0
When I create just a basic application with a form and some buttons etc. it does work on my device.
|
|
|
|
|
Hi everyone!
is that possible to edit labels of every column header of listView (if it is showing details view). Normally if we add a subitem to rows we cannot edit it.
What can we use similar to listView (Detail View) to edit every column in list.
Thanks.
|
|
|
|
|
Search the property Text of ColumnHeader object.
Example:
ListView1.Columns[0].Text = "My Favorite Column";
|
|
|
|
|
Hello all...
I looked around the forum for a solution, or a good heads up on my problem. Either blind,
or there really isn't an answer posted. So here's my situation.
I need to search through folders for files with a certain file extention [*.mp3]
And display the path to those files in a treeview.
So if a folder has MP3 files, it should display the folder name in the treeview, if not don't add to treeview.
If a folder does not contain MP3s, but its sub-folder(s) do, add folder name + subs to the treeview.
And so on and so forth...
[hmmm hope I'm making myself clear... ]
In the end, I should end-up with a treeview with folders containing mp3 files and folders whos
sub-folders contain mp3 files. In a "Window-Explorer-ish" style.
Then, in the end, when clicking on the node it lists the files in a listview...
Got the searching for MP3 files done, and displaying the contained files in the listview also done.
The trouble right now, is it's adding all folders and subs..even the ones not containing MP3s.
Any ideas anyone ?
Thanks...
LoneFerret
ps: If it helps, I can always paste the code I got so far... but it ain't pretty...
____________________________________________
Cross my heart, smack me dead...stick a lobster on my head.
|
|
|
|
|
If your search algorithm returns the fully qualified path to the MP3 file, you can use Path.GetDirectoryName(string) to return the directory information for the file. From that you can build your tree structure. You might need to split the string on the "\" character depending on how you want the tree to look.
If the search doesn't already return the fully qualified path, you may need to use Path.GetFullPath(string) , which will return the fully qualified path based on the current directory.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|