|
It's commonly used when using external C/C++ dlls (PInvoke).
When a structure is being passed as a parameter to an external function then the called C/C++ function needs to know exactly where to find the relavent parts of the structure in memory. It does this using byte offsets from the start address (pointer) of the struct.
Imagine you had this structure
public struct MyStruct
{
public byte a;
public int b;
} Without specifying the LayoutKind , this could end up being layed out in memory with b first. This would be catastrophic for the external function as it would assume the fields to be layed out in sequence - so with a first. As a result the data retrieved from memory would be incorrect. To make sure that the sequence of fields is preserved, we use LayoutKind.Sequential .
Another common one is LayoutKind.Explicit (most commonly when used with C/C++ unions). Here you explicitly state the offset for each field using the FieldOffset attribute.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hello, I'm building a database WinForm application.
The data objects in my first application where based up on SQLDataConnector, DataSet, DataTables and SQLDataAdapter.
Now I moved on and I write Data object classes, which I fill with a SqlDataReader. Modifying the record is done by straight INSERT, UPDATE and DELETE queries written in a Data Object DB Class.
The technique is out of the book => Murach's ADO.Net 3.5 LinQ and the Entity Framework. After studying different technique I decided not to go for Entity Framework but hang around with writing my own data classes, making use of binding with data objects and most important ... understanding what happens under the Engine Cowling.
So far so GOOD.
The client interface works fine, but I like to give the User feedback as soon she/he is changing the content in one of the bounded controls (Textbox, comboBox, ect). In such case I like to show a pencil Icon on the form indicating the content has been changed. So I like to capture an event as soon the record becomes "DIRTY".
This way I can decided if an Update is required when the user clicks the button "Save and Close" (just like with leaving a MS Outlook contact form). If the 'IsDirty' property is 'false' the form just should close. Else it should write the changes back to the SQL server in advance of closing.
I studied the BindingSource control, but I cannot find an 'IsDirty' property as well no event related to this.
I found some articles on the web indicating the same problem. But the code samples are not providing a solution for me.
CONCREET: I like to customize the BindingSource by simply adding an "IsDirty" property and an "IsDirtychanged" event. Will this be an easy one????
Your help is most appreciated!
With kind regards,
Arjen Groeneveld
|
|
|
|
|
ArjenGroeneveld wrote: I studied the BindingSource control, but I cannot find an 'IsDirty' property as well no event related to this.
The BindingSource has a CurrentItemChanged -event[^] that might be of help.
ArjenGroeneveld wrote: CONCREET: I like to customize the BindingSource by simply adding an "IsDirty" property and an "IsDirtychanged" event. Will this be an easy one????
Meh, that's an unfair question! It would include subclassing the BindingSource , adding a field, an event, and the wiring for it. You'd also need a testproject, time and documentation - and you can ask additional questions here
I are Troll
|
|
|
|
|
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.)
|
|
|
|
|