|
Okay, Can you help me with the code?
Kind regards Arjen
|
|
|
|
|
ArjenGroeneveld wrote: Okay, Can you help me with the code?
If you want to save the Dirty-field along with the binding, then I'd suggest overriding the Binding class, and not the BindingSource . This might give you a start for a test-form, and having a property in a derived class, using databinding;
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
namespace Example
{
public class MyBinding : Binding
{
bool _isDirty;
public bool IsDirty
{
get
{
return _isDirty;
}
set
{
if (_isDirty != value)
_isDirty = value;
}
}
public MyBinding(string propertyName, object DataSource, string dataMember)
:base(propertyName, DataSource, dataMember)
{
}
}
public class Form1 : System.Windows.Forms.Form
{
static void Main()
{
Application.Run(new Form1());
}
private TextBox textBox1;
private ListBox listBox1;
private MyBinding myBinding;
public Form1()
{
InitializeComponent();
}
private void InitializeComponent()
{
SuspendLayout();
listBox1 = new ListBox();
textBox1 = new TextBox();
textBox1.Location = new Point(16, 68);
textBox1.Size = new Size(144, 20);
listBox1.Location = new Point(16, 8);
listBox1.Size = new Size(144, 50);
ClientSize = new Size(176, 100);
Controls.Add(textBox1);
Controls.Add(listBox1);
Name = "Form1";
Text = "Form1";
Load += new EventHandler(Form1_Load);
ResumeLayout(false);
}
private void Form1_Load(object sender, System.EventArgs e)
{
DataTable dt = new DataTable("employee");
dt.Columns.Add("firstname");
dt.Columns.Add("lastname");
dt.Rows.Add("john", "doe");
dt.Rows.Add("johnny", "walker");
listBox1.DataSource = dt;
listBox1.DisplayMember = "firstname";
myBinding = new MyBinding("Text", listBox1.DataSource, "lastname");
textBox1.DataBindings.Add(myBinding);
}
}
} Enjoy
I are Troll
|
|
|
|
|
Hello,
The end result I have in mind is an extended BindingSouce control, which is having an "IsDirty" property and an "IsDirtyChange" event.
The "IsDirtyChange" should only trigger when the User is making a change in one of the bounded controls.
I did some searching in FrameWork and I put the following together, but this code does not trigger when a user changes the content in a control. So something is missing.
Extended BindingSource coding...
namespace ACMAD.Business
{
class exBindingSource : BindingSource
{
// Internal variable
private bool flgIsDirty = false;
// Event
public event EventHandler IsDirtyChanged;
protected virtual void OnDirtyChanged(EventArgs e)
{
if (IsDirtyChanged != null)
{
IsDirtyChanged(this, e);
}
}
public bool IsDirty
{
get
{
return flgIsDirty;
}
set
{
flgIsDirty = value;
}
}
protected override void OnBindingComplete(BindingCompleteEventArgs e)
{
base.OnBindingComplete(e);
if (e.BindingCompleteContext == BindingCompleteContext.DataSourceUpdate)
{
if (!flgIsDirty && (e.BindingCompleteState == BindingCompleteState.Success) && e.Binding.Control.Focused)
{
flgIsDirty = true;
OnDirtyChanged(EventArgs.Empty);
}
}
}
protected override void OnCurrentChanged(EventArgs e)
{
base.OnCurrentChanged(e);
if (flgIsDirty == true)
flgIsDirty = false;
}
}
}
Form coding
I placed the exBindingSource on the form and connected an textbox to it.
One record is loaded with:
// Test purpose
exBindingSource1.Clear();
exBindingSource1.Add(ac_Model);
And I added an event
private void exBindingSource1_IsDirtyChanged(object sender, EventArgs e)
{
textBox1.Text = exBindingSource1.IsDirty.ToString();
}
The idea is that when the user makes a change to Textbox1 that Textbox2 is filled with the exBindingSource1.IsDirty value.
But ... nothing happens..
Your help is most appreciated.
With kind regards,
Arjen Groeneveld
|
|
|
|
|
I've added a theoretical OnCurrentItemChanged , but my DataGridView won't let me edit the collection. I can't test the code until tomorrow
protected override void OnCurrentItemChanged (System.EventArgs e)
{
base.OnCurrentItemChanged (e);
if (IsDirty == false)
IsDirty = true;
}
I are Troll
|
|
|
|
|
Hi, just want to ask if you solve your question, because right now I'm having problem same as yours, I would be thankful if you can share it, thanks.
By the way, what type of your datasource you used in extended bindingDataSource?
thank you..
|
|
|
|
|
I have a datagrid binded to a datatable. I am filling the datatable for example with 4 rows. When i then try to show the datagrid rows in the windows form the the datagrid inserts 4 empty rows.
it point notmally to the datatable but the cell of the datagrid is empty. if i put let say 10 rows in table then again in the datagrid i see 10 rows but empty cells.
DataGridView1.AutoGenerateColumns = true;
DataGridView.DataSource =DT;
DataGridView1.Columns.Add("CCH_Index", "CCH_Index");
DataGridView1.Columns[0].DataPropertyName = "CCH_Index";
DataGridView1.Columns[0].ReadOnly = true;
this happens when i select particular rows from datasource to display;
|
|
|
|
|
tasossty wrote: if i put let say 10 rows in table then again in the datagrid i see 10 rows but empty cells.
That's strange; no errors at all, and displaying the correct amount of records, without data? Can you show us the SQL statement? Or the code required to reproduce the error?
tasossty wrote: DataGridView1.AutoGenerateColumns = true;
DataGridView.DataSource =DT;
I'm assuming that there's a typo in the line where you assign the DataSource, since it would be assigned to DataGridView1.DataSource .
Some things that you might want to check;
- Is the foreground color of a cell different from it's backcolor?
- Is there an error with "displaying" the data, or "fetching" the data? In other words, can you display data using another control, like for example, a TextBox ?
- Can you set a breakpoint on the line where you make the columns readonly, and see if there's the correct data present in DataGridView1.DataSource .
I are Troll
|
|
|
|
|
|
C# is definitely not as fast as a native language, but it is much faster then java...
|
|
|
|
|
Most statements about language choice and resulting performance are crap.
Are they referring to "black box" performance (i.e. I know nothing, I don't care, just show me)? or optimal code for each? or something pragmatic in-between?
If you want to solve one problem in 3 languages, you probably are thinking in one language, designing and implementing the code, then porting to the other two. And it is likely the first one will end up to be the fastest.
However, if you know the 3 languages equally well, and would start from scratch each time, the results may already be different. Then the tools and the compiler settings come in.
I have seen Java and C# beat C and C#, and vice versa. It all depends.
If you need to know, for a particular application, and a particular person or team or programming style, find out what the kernel of the app is, and give it a try, everything else is BS.
|
|
|
|
|
devvvy wrote: Or am I mistaken, that .NET really is a [significantly] slower...?
You can optimize your code in any language if you know the internals and other pitfalls. So comparing one language with other language in terms of speed is just pointless. Also the test shown in that web page uses .NET framework 1.1 which is quite old.
I'd say the link you pointed out is just crap.
Best wishes,
Navaneeth
|
|
|
|
|
They tested only .NET 1.1, and clearly only in 32bit mode. The performance characteristics of .NET 2.0 are very different (less boxing/unboxing for example) and the 64bit version is also completely different (which extra optimizations which are not done by the 32bit version, and of course 64bit math is basically twice as fast)
|
|
|
|
|
any more conclusive references online anyone?
dev
|
|
|
|
|
Sadly the best language benchmark out there doesn't include C# properly, that is, they use Mono which obviously has completely different performance characteristics.
Also there isn't really just "1 number" that says how fast a language is of course, for example, C# has unsafe pointers making image manipulation several orders of magnitude faster than in Java, but common Java JIT compilers have more SSE capabilities than the JIT compiler in the CLR, so numerical algorithms may be faster in Java (provided they do not use any trig, which is a disaster in Java) - but then of course C++ will beat both when it comes to raw numerical power (as seen here[^] out of the top 6 fastest languages, 5 are C or C++, Java isn't far behind and C# was tested with Mono so it's result is essentially useless)
|
|
|
|
|
I wanted to crop multiple images at the same time.I tried to integrate the code for cropping single image with my code and got messed up.Can somebody help with this code.....
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
namespace batch_image_editor
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
{
}
private void addphotos_Click(object sender, EventArgs e)
{
opend1.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*";
opend1.Multiselect = true;
imageList.Images.Clear();
listView1.Items.Clear();
if (opend1.ShowDialog() == DialogResult.OK)
{
listView1.View = View.LargeIcon;
imageList.ImageSize = new Size(50, 50);
for (int c = 0; c < opend1.FileNames.Length; c++)
{
Image i = Image.FromFile(opend1.FileNames[c].ToString());
Image img = i.GetThumbnailImage(256, 256, null, new IntPtr());
imageList.Images.Add(img);
}
listView1.LargeImageList = imageList;
for (int j = 0; j < imageList.Images.Count; j++)
{
ListViewItem lstItem = new ListViewItem();
lstItem.ImageIndex = j;
listView1.Items.Add(lstItem);
}
this.cropToolStripMenuItem.Enabled = true;
this.resizeToolStripMenuItem.Enabled = true;
this.compressToolStripMenuItem.Enabled = true;
this.greyScaleToolStripMenuItem.Enabled = true;
this.save.Enabled = true;
}
}
private void cropToolStripMenuItem_Click(object sender, EventArgs e)
{
listView1.LargeImageList = null;
ImageList imgListNew = new ImageList();
for (int i = 0; i < listView1.Items.Count; i++)
{
if (listView1.Items[i].Checked)
{
frmCropInfo infoForm = new frmCropInfo();
infoForm.cropOK += new CropInfoEventHandler(infoForm_cropOK);
infoForm.Show();
}
}
}
void infoForm_cropOK(object sender, CropInfoEventArgs e)
{
Image img = this.cropImage(Image img, new Rectangle(e.X, e.Y, e.Width, e.Height));
}
private Image cropImage(Image img, Rectangle cropArea)
{
Bitmap bmpImage = new Bitmap(img);
Bitmap bmpCrop = bmpImage.Clone(cropArea,
bmpImage.PixelFormat);
return (Image)(bmpCrop);
}
}
} }
thanking you in advance
|
|
|
|
|
|
without any details on how you check single data and bulk I can't help you.
|
|
|
|
|
What detail u want?
code or database or both?
please tell
|
|
|
|
|
code mostly. maybe it's a bug.
A small table detail like:
Tbl1
=========
ID
Name
..
Tbl2
======
FKID
...
and the code that checks.
I have no ideea what and where it goes wrong.
|
|
|
|
|
OK
when i put single roll no. data in table and get it check than ans. is right.
but when check for all the roll nos. than that same roll no. get wrong ans.
|
|
|
|
|
Will you please elaborate….
Thanks
Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
Hello,
I have a textbox in my window application.
I want to be able to write into the textbox even if the application window not in focus (not "first" on the screen).
How can i do it?
If i need to use events for it , i don't know exacly how to write an event and where to put each code piece (the event handler etc.)
|
|
|
|
|
Sounds like a weird requirement. Don't you think it will be weird for the users? I mean you type in something on a form and it is shown at a very different location.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
I am trying to understand what you want to achieve. Is it:
"I have a windows app which contains a textbox. Even if the windows app does not have the focus, but Notepad does, I want user input to go into my textbox"
or
"I have a windows app which contains a textbox. Even if the windows app does not have the focus, but Notepad does, I want my app to be able to insert text into my textbox"
The former is not normal at all - and I don't think it can be done.
The latter happens without any work at all.
If these do not describe what your problem is, then please try to restate it and we'll see what we can do.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
The purpose of it is that i want the program will read data from a barcode reader and then display it on the textbox, even if the window is not it focus
|
|
|
|
|