lundi 30 mars 2015

System.Data.DataRowView shows in winforms combobox instead of actual data

After I load my combobox, it displays System.Data.DataRowView instead of data. I am using the correct column names as returned from the stored procedure (TimeframeDesc and TimeframeCode).


I get the message 'Cannot bind to the new display member' when debugging.



private bool loadTimeframeList(out string msg)
{
msg = "";
string spName = "schemaExec.SelTimeframeCode";
bool result = true;
SqlCommand cmd = new SqlCommand(spName);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = _sqlConn;

try
{
SqlDataAdapter rdr = new SqlDataAdapter(cmd);
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
rdr.Fill(dt);

cbTimeframe.DisplayMember = "TimeframeDesc";
cbTimeframe.ValueMember = "TimeframeCode";
cbTimeframe.DataSource = dt;
}
catch (Exception ex)
{
result = false;
msg = "Could not load Timeframe Codes" + Environment.NewLine + ex.Message;
}
return result;
}

How can I reset a Windows Form?

I have a form in C# that has items such as buttons, a background, and text. When a button is clicked, I want the form to go to a blank state (nothing on the form) so I can add other things. I don't want to have to have Form1 and Form2 that switch between each other. Simply, I just don't want to switch between two different forms.


When trying to upload a file to my own ftp server i created using filezilla i'm getting The requested URI is invalid for this FTP command why?

This my ftp upload method:



string fff = "";
public string[] GetFileList()
{
string[] downloadFiles;
StringBuilder result = new StringBuilder();
WebResponse response = null;
StreamReader reader = null;
try
{
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + f.Host + "/"));
fff = "ftp://" + f.Host + "/";
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(f.Username, f.Password);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
reqFTP.Proxy = null;
reqFTP.KeepAlive = false;
reqFTP.UsePassive = false;
response = reqFTP.GetResponse();
reader = new StreamReader(response.GetResponseStream());
string line = reader.ReadLine();
while (line != null)
{
result.Append(line);
result.Append("\n");
line = reader.ReadLine();
}
result.Remove(result.ToString().LastIndexOf('\n'), 1);
return result.ToString().Split('\n');
}
catch (Exception ex)
{
if (reader != null)
{
reader.Close();
}
if (response != null)
{
response.Close();
}
downloadFiles = null;
return downloadFiles;
}
}


For the test fff contain: ftp://127.0.0.1/ And in the filezilla i see in the log:



(000006)30/03/2015 21:59:24 - (not logged in) (127.0.0.1)> Connected on port 21, sending welcome message...
(000006)30/03/2015 21:59:24 - (not logged in) (127.0.0.1)> 220-FileZilla Server version 0.9.50 beta
(000006)30/03/2015 21:59:24 - (not logged in) (127.0.0.1)> 220-written by Tim Kosse (tim.kosse@filezilla-project.org)
(000006)30/03/2015 21:59:24 - (not logged in) (127.0.0.1)> 220 Please visit http://ift.tt/13OgtXY
(000006)30/03/2015 21:59:24 - (not logged in) (127.0.0.1)> disconnected.


But the file is not uploaded instead i'm getting exception message in my program:


The requested URI is invalid for this FTP command



System.Net.WebException was caught
HResult=-2146233079
Message=The requested URI is invalid for this FTP command.
Source=System
StackTrace:
at System.Net.FtpWebRequest.CheckError()
at System.Net.FtpWebRequest.GetResponse()
at FTP_ProgressBar.FtpProgress.GetFileList() in c:\ftp_progressbar\FTP_ProgressBar\FtpProgress.cs:line 342
InnerException:


Line 342 is:



response = reqFTP.GetResponse();


In fileZilla i created a user i have a password and user name i added a directory and gave a permission to write delete read for files and directories.


Add control to the parent control at runtime

I need to add a control added at runtime to the parent control (panel) I can set the properties of the object (PictureEdit) but how do i display it...add it to the parent control??? thank you



protected override void OnPaint(PaintEventArgs pe)
{
PictureEdit halfmoon = new PictureEdit();
halfmoon.Location = new Point(36, 3);
halfmoon.BorderStyle = BorderStyles.NoBorder;
halfmoon.Properties.SizeMode = PictureSizeMode.Squeeze;
halfmoon.Image = Properties.Resources.picture;
}

Mouse click on dom perfomance issues geckofx(embedded win xp sp3)

I need help to point out the bottleneck of my app. I am using geckofx browser control in winforms app, running on winxp sp3. Click event propagate to dom so slow - it might take up to couple seconds. Some log records with nlog




2015-03-30 19:05:26.3085 TRACE WM_LBUTTONDOWN
2015-03-30 19:05:27.0585 TRACE DomClick -Gecko.DOM.GeckoButtonElement



There is no such problem in win7 - it running fast on it. Here code of my mainform MainForm.cs



….
public MainForm()
{

InitializeComponent();
this.WindowState = FormWindowState.Maximized;
//catching win messages
Application.AddMessageFilter(this);

Gecko.GeckoPreferences.User["layers.accelerate-all"] = true;

this.Load += MainForm_Load;


}

void MainForm_Load(object sender, EventArgs e)
{
LogAllEvents();

}


private void LogAllEvents()
{
geckoWebBrowser.WindowSetBounds += (s, e) => { _logger.Trace("WindowSetBounds - " + e.Bounds); };
geckoWebBrowser.Paint += (s, e) => { _logger.Trace("Paint -" + e.ClipRectangle); };
geckoWebBrowser.Invalidated += (s, e) => { _logger.Trace("Invalidated -" + e.InvalidRect); };
geckoWebBrowser.DomClick += (s, e) => { _logger.Trace("DomClick -" + e.Target.ToString()); };
geckoWebBrowser.DocumentCompleted += (s, e) => { _logger.Trace("DocumentCompleted -" ); };
}



public bool PreFilterMessage(ref Message m)
{

if (m.Msg == WM_LBUTTONDOWN)
{
_logger.Trace("WM_LBUTTONDOWN");
return false;
}
else
if (m.Msg == WM_LBUTTONUP)
{
_logger.Trace("WM_LBUTTONUP");
return false;
}
else
return false;

}


MainForm.Designer.cs




// BrowserHolder
//
this.BrowserHolder.Controls.Add(this.geckoWebBrowser);
this.BrowserHolder.Dock = System.Windows.Forms.DockStyle.Fill;
this.BrowserHolder.Location = new System.Drawing.Point(0, 28);
this.BrowserHolder.Name = "BrowserHolder";
this.BrowserHolder.Size = new System.Drawing.Size(1180, 554);
this.BrowserHolder.TabIndex = 2;
//
// geckoWebBrowser
//
this.geckoWebBrowser.Dock = System.Windows.Forms.DockStyle.Fill;
this.geckoWebBrowser.Location = new System.Drawing.Point(0, 0);
this.geckoWebBrowser.Name = "geckoWebBrowser";
this.geckoWebBrowser.Size = new System.Drawing.Size(1180, 554);
this.geckoWebBrowser.TabIndex = 0;
this.geckoWebBrowser.UseHttpActivityObserver = false;



BrowserHolder is panel that wrap webbrowser control.


I don’t have any clue what’s going on, cpu usage under 10 percent. Here’s my machine: ms windows embedded POSready 2009 ver2.0 service pack3 Intel Atom D2500 ,1.86 ghz ,1.98 gb of ram Geckofx 16 and 31 –same result – very slow click


Creating a find dialog in C# winforms rtxtbox

So for this assignment in class I'm making a richtextbox editor in C# winforms, in this assignment I have to include a find function, but I can't seem to get the hang of it


Here's my code up until now:



Form findDialog = new Form();
findDialog.Width = 500;
findDialog.Height = 142;
findDialog.Text = "Zoeken";
Label textLabel = new Label() { Left = 10, Top = 20, Text = "Zoek naar:", Width = 100 };
TextBox inputBox = new TextBox() { Left = 150, Top = 20, Width = 300};
Button search = new Button() { Text = "Zoek", Left = 350, Width = 100, Top = 70 };
search.Click += (object sender, EventArgs e) => { findDialog.Close(); };
findDialog.Controls.Add(search);
findDialog.Controls.Add(textLabel);
findDialog.Controls.Add(inputBox);
findDialog.ShowDialog();
return (string)inputBox.Text;


And I'm calling the function by using



string searchValue = SearchDialog();


Thanks in advance


DrawImage Height Parameter Not Working

I am making a WinForms app using VS2012 c++/cli and using DrawImage to display HD images captured from a webcam.


The images are 1920 x 1080 bitmaps that I am trying to display on a Panel control. The Panel is 240 x 135 (i.e., exactly 1/8 of the HD image).


I am calling DrawImage as follows:



System::Drawing::Rectangle destRect = System::Drawing::Rectangle(0,0,Cam0Panel->Width,Cam0Panel->Height);
g->DrawImage(b,destRect);


This should specify to draw the image at the relative 0,0 location on the panel and size the image to be 240 x 135. However, the image will not display.


If I change the Height parameter to specify the Panel->Bottom (which is the absolute position in the app - ~630), the image does display and is correctly sized for width but is not correctly sized for height.


Any idea what I am doing wrong or how to correctly resize and display the image?


Here is a complete version of the code.



void Cam0Panel_Paint( Object^ /*sender*/, System::Windows::Forms::PaintEventArgs^ e )
{
System::Drawing::Bitmap^ b = ImageWinArray[CHANNEL_SELECT0];
Graphics^ g = e->Graphics;

g->InterpolationMode = System::Drawing::Drawing2D::InterpolationMode::Bilinear;
g->CompositingMode = System::Drawing::Drawing2D::CompositingMode::SourceCopy;
System::Drawing::Rectangle destRect = System::Drawing::Rectangle(0,0,Cam0Panel->Width,Cam0Panel->Bottom);

g->DrawImage(b,destRect);
}


Thanks for any help.