|
Thanks for the reply.
I tried that and I get the error;
"Cannot create a child list for field People."
This code is generated automatically when you set up the data binding for the textbox in the designer so should be okay, right???
John.
|
|
|
|
|
You got that error where?
If you actually read the documentation for the Control.BindingContext , it clearly states what I said - the binding context must be the same as what was used to bind the control. For your TextBox in question, they are not the same.
You could also try changing the binding for your ListBox to what the TextBox uses and changing your BindingContext accordingly as well.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
The full error is:
An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll<br />
<br />
Additional information: Cannot create a child list for field People.
I single stepped through the program and the error happens after this line of code runs (every line of code in the Form1 constructor steps through okay but it fails when the last line has been executed and it returns to this line. If I break into it is breaks on the line after this one - int i = 0 ).
Application.Run(new Form1());
I read the documentation. Can you get it to work using the designer interface? Or even via code?
John.
|
|
|
|
|
You are right! When I tried your solution the first time I changed the second parameter but not the third. When I made both changes it worked.
So it looks like a bug in the designer. When I set the DataBindings in the property window of the TextBox it generates code the incorrect way. So now I am not binding that way but via my own code.
Thanks for your help.
John.
|
|
|
|
|
Hi there,
I am attempting to add a calculation via text box's?....unfortunately I am having no luck, has anybody got a sample code in calculating numbers/data ect... please help.
cheers
SM
|
|
|
|
|
I didn't get you properly.Please make it little clear.
Sreejith S S Nair
|
|
|
|
|
Hi Sreejith
I am building a new application where i want to add labour + material costs and I need to calculate those two items to equal in a seperate text box. I am using Microsoft Visual studio to assist me, but I don't really know how to use the properties section that well.
all i wan't to do is add two data types together and recieve a result whilst the application is live?
cheers
SM
|
|
|
|
|
for eg you are getting the two required values in a textbox then system will treat that values as string.so what you want to do first is, convert the two textbox values into numeric form.for eg. int or float or anything.
int labourcost=int.parse(textbox1.text);
int materialcost=int.parse(textbox2.text);
now you have numeric types of your input.
next is
resulttextbox.text=(labourcost+materialcost).ToString();
is this fine.
Sreejith S S Nair
|
|
|
|
|
A minor addition to the previous post by Sreejith:
As your TextBoxes can contain anything other than the string representation of a number, you should handle the FormatException of the Parse method.
<br />
try<br />
{<br />
int labour = int.Parse(textboxLabour.Text);<br />
int material = int.Parse(textboxMaterial.Text);<br />
}<br />
catch (System.FormatException)<br />
{<br />
}<br />
|
|
|
|
|
thanks dear
Sreejith S S Nair
|
|
|
|
|
Never mind
Let's hope stevemasters22 got what he wanted.
|
|
|
|
|
Hi Stefan,
I cant get it working...below is the code....pls help...all I wan't is for textbox3 to = textbox1 + textbox2, when i tab to textbox 3.
SM
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication5
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(64, 56);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(184, 56);
this.textBox2.Name = "textBox2";
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(112, 104);
this.textBox3.Name = "textBox3";
this.textBox3.TabIndex = 2;
this.textBox3.Text = "";
this.textBox3.TextChanged += new System.EventHandler(this.textBox3_TextChanged);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void textBox3_TextChanged(object sender, System.EventArgs e)
{
try
{
int labour = int.Parse(textBox1.Text);
int material = int.Parse(textBox2.Text);
textBox3.Text =textBox1+textBox2.ToString();
}
catch (System.FormatException)
{
//handle exceptions by assigning default values for example
}
}
}
}
|
|
|
|
|
The problem is your using the TextChanged event of TextBox3. Don't...don't use TextBox3 events to fire off the calculation. What you should be doing is performing the calculation on the Leave or LostFocus events of the other two TextBoxes. With a little modification to the TextBox properties, you could even use the Validating event. In any case, when you hanlde any of these events, you can do some validation on Textbox1 and Textbox2 so you can make sure that your not trying to add '100 + whoknowswhat'. Then all you do is Total = Decimal.Parse(Textbox1.Text) + Decimal.Parse(Textbox2.Text), then Textbox3.Text = Total.ToString().
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi Dave,
I cant work it out chief, I am too much of a beginner(bloody hopeless)....could you pls show me a sample.
cheers
SM
|
|
|
|
|
You'll have to wait until I get home to put this sample together. I can't install the Framework and/or VS.NET on any machine here at work for security reasons...
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
[EDIT]
I've reposted this because I found a couple typos after I posted it...
OK. Here's the modified sample. Warning!!!! This is COMPLETELY UNTESTED CODE!
I'm still at work, with nothing much else to do and wrote this from memory using Notepad of all things!
But, Stephan is right about experimenting with the events. Just try writing code for the various event handlers. It doesn't have to be anything special, maybe just displaying a descriptive MsgBox when the event handler is called.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication5
{
public class Form1 : System.Windows.Forms.Form
{
Single m_Labour = 0.0;
Single m_Material = 0.0;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
this.textBox1.Location = new System.Drawing.Point(64, 56);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
this.textBox1.Leave += new System.EventHandler(this.textBox1_Leave);
this.textBox2.Location = new System.Drawing.Point(184, 56);
this.textBox2.Name = "textBox2";
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
this.textBox2.Leave += new System.EventHandler(this.textBox2_Leave);
this.textBox3.Location = new System.Drawing.Point(112, 104);
this.textBox3.Name = "textBox3";
this.textBox3.TabIndex = 2;
this.textBox3.Text = "";
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void textBox1_Leave(object sender, System.EventArgs e)
{
m_Labour = ValidateInput(textbox1);
textbox1.Text = m_Labour.ToString("##,###.00");
UpdateTotalTextBox();
}
private void textBox2_TextChanged(object sender, System.EventArgs e)
{
m_Material = ValidateInput(textbox2);
textbox2.Text = m_Material.ToString("##,###.00");
UpdateTotalTextBox();
}
private Single ValidateInput(ref TextBox textboxToValidate)
{
Single returnValue;
try
{
returnValue = Single.Parse(textboxToValidate.Text);
}
catch (Exception e)
{
returnValue = 0;
}
return returnValue;
}
private void UpdateTotalTextbox()
{
Single jobTotal = m_Labour + m_Material;
textBox3.Text = jobTotal.ToString("##,###.00");
}
}
}
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
As Dave said, it's wrong to use the TextChanged event of textBox3, cause this one is fired when its text changes, what means that your result changes.
Instead add event handler for the other two TextBoxes and fill them with the calculation which your now doing in textBox3_TextChanged . Now your result gets updated every time you change one of your TextBoxes.
Afterwards you can delete the textBox3_TextChanged .
As Dave also mentioned you could use other events than TextChanged like LostFocus or so. This would affect that your reslut isn't updated until you leave your Textbox and not every time you changed the contained text.
I advise you to experiment a bit with the differnt events. A good way to practically see how the are working and when they are raised, is to add an event handler for the specific event and set a break point into it.
I think it's important to go through this by yourself to get a deeper understanding of what your are doing. In the long way it's much better than getting a piece of code posted and simply using it.
Good luck
|
|
|
|
|
|
please write your queary before clicking the save button
Sreejith S S Nair
|
|
|
|
|
please write your queary before clicking the sumit button
Sreejith S S Nair
|
|
|
|
|
Hi!
Now what...
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hi ,i come from china,as a beginner.i met with some diffculties in my new project ,that is how to improve the speed of reading data from CD-ROM ?i built two FileStreams,one is Read data from CD-ROM,another is write data to harddisk,there is a buffer between two operation, can you give me some effesional advice to complete this new project,thank you !if you have some advice or good method please sent email to agu9899@163.com .The following is my source code :
using System;
using System.IO;
using System.Collections;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Messaging;
namespace EditDVDFile
{
///
/// ClsCompex 的摘要说明。
///
public class ClsCompex
{
public static int m_progressVal;
public static bool m_bWork=false;//是否在进行读写操作
class CFileReadBuf
{
public int m_nBufLen=1048576;//1048576;
public byte[] m_Buf= new byte[1048576];//[1048576];
public int m_nReadLen;
public bool m_bWrite=false;//是否在进行写操作
public IAsyncResult m_AsyncResult;
}
bool m_bOneWork;
long t1,t0;
CFileReadBuf m_FileBuf1=new CFileReadBuf();
CFileReadBuf m_FileBuf2=new CFileReadBuf();
public FileStream m_FileStreamRead;
FileStream m_FileStreamWrite;
AsyncCallback CallBackMethodRead;
AsyncCallback CallBackMethodWriteEnd;
public ArrayList m_arFileName=new ArrayList();
public ClsCompex()
{
}
public void DVDCompex(ArrayList arTemFileName,string DesPath)
{
m_bWork=true;
//使用文件名来构造FileStream流
m_arFileName=arTemFileName;
string strFileName=arTemFileName[0].ToString();
m_FileStreamRead =new FileStream(strFileName,FileMode.Open,FileAccess.Read, FileShare.ReadWrite,1048576,true);
m_FileStreamWrite=new FileStream(DesPath,FileMode.Append, FileAccess.Write, FileShare.ReadWrite, 1048576, true);
//构造回调方法
CallBackMethodRead =new AsyncCallback(ReportReadingProgress);
CallBackMethodWriteEnd =new AsyncCallback(ReportWriteEndProgress);
//启动异步读取操作
m_bOneWork=true;
t0 = Environment.TickCount;
//System.Diagnostics.Debug.WriteLine("Start Reading Progress......");
m_FileStreamRead.BeginRead(m_FileBuf1.m_Buf,0,m_FileBuf1.m_nBufLen,CallBackMethodRead,m_FileBuf1);
}
public void ReportWriteEndProgress(IAsyncResult asyncResult)
{
}
public void ReportReadingProgress(IAsyncResult asyncResult)
{
try
{
//System.Diagnostics.Debug.WriteLine("..........ReportReadingProgress..........");
CFileReadBuf m_FileBufRead;
CFileReadBuf m_FileBufWrite;
if(m_bOneWork)
{
m_FileBufRead=m_FileBuf1;
m_FileBufWrite=m_FileBuf2;
m_bOneWork=false;
}
else
{
m_FileBufRead=m_FileBuf2;
m_FileBufWrite=m_FileBuf1;
m_bOneWork=true;
}
m_FileBufRead.m_nReadLen=m_FileStreamRead.EndRead(asyncResult);
//System.Diagnostics.Debug.WriteLine("Current stream position is : "+m_FileStreamRead.Position.ToString()+" byte");
if(m_FileBufWrite.m_bWrite)
{
m_FileStreamWrite.EndWrite(m_FileBufWrite.m_AsyncResult);
m_FileBufWrite.m_bWrite=false;
}
if(m_FileBufRead.m_nReadLen==0)
{
t1 = Environment.TickCount;
//System.Diagnostics.Debug.WriteLine(m_arFileName[0].ToString()+"ReportWritrEndProgress "+((t1-t0)/1000)+"s");
m_FileStreamRead.Close();
m_arFileName.RemoveAt(0);
if (m_arFileName.Count>0)
{
string strTemName=m_arFileName[0].ToString();
m_FileStreamRead=new FileStream(strTemName,FileMode.Open,FileAccess.Read, FileShare.ReadWrite,1048576,true);
m_FileStreamRead.BeginRead(m_FileBufWrite.m_Buf,0,m_FileBufWrite.m_nBufLen,CallBackMethodRead,m_FileBufWrite);
}
else
{
m_FileStreamWrite.Close();
}
m_bWork=false;
return;
}
m_FileBufRead.m_bWrite=true;
m_FileBufRead.m_AsyncResult=m_FileStreamWrite.BeginWrite(m_FileBufRead.m_Buf,0,m_FileBufRead.m_nReadLen,null,null);
//文件读取结束
m_FileStreamRead.BeginRead(m_FileBufWrite.m_Buf,0,m_FileBufWrite.m_nBufLen,CallBackMethodRead,m_FileBufWrite);
}
catch(Exception e)
{
MessageBox.Show(e.Message,"文件读写错误提示");
m_FileStreamRead.Close();
m_FileStreamWrite.Close();
GC.Collect();
}
}
}
}
|
|
|
|
|
Use a smaller buffer. A 4 KB block (4096) is typically a good buffer size. If you use a larger block, more data must be read and written so the CD sits idly by.
Also, just a good programming tip: define your buffer size as a constant variable so you avoid any possible screw-ups (like forgetting a number when typing). This also makes it easy to change, since you change only this constant variable and recompile:
private const int BufferSize = 4096;
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I need to know if my code is right to enable or disable any object in C#.net
I use if condition.. is there other way to do it?
private void optBCLA01001_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(optBCLA01001.SelectedIndex == 0)
{
optBCLA01006.Enabled = true;
}
}
|
|
|
|
|
Kind of...It all depends on what a 'optBCLA01006' is. A button?...Checkbox?... For just about all of the usual form controls like buttons and checkboxes and radio buttons, textboxes, ... this is true.
BTW: Those variable names are HORRIBLE because they are not descriptive of anything they represent.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|