|
Anonymous wrote:
implement a Save File Dialog and a Open File Dialog in a DataGrid Control
Implement one IN a Datagrid Control? No, it's not...
But if you talking about exporting the data in the control to a file, you would have to either serialize the data out to a binary or XML file on the click of a button or menu item maybe, it's up to you, or you could write your own export/import code easily enough.
RageInTheMachine9532
|
|
|
|
|
Yeah,
I have this datagrid that gets populated with data from the database. One of the requirements is that the user should be allowed to specify a file name to save details of each record into. So, inorder to specify a filename, I wanted to open a file dialog to allow the user to choose a directory location. Actually the user will not do the "Save" operation there. It will happen later on. The user only needs to specify a location on the hard drive concatenated with a file name.
Let me know if that changes your perspective of the problem.
Thanks
Alex
|
|
|
|
|
Yeah it does. But you don't implement a SaveDialog in your DataGrid. It's done on your form, or anywhere it would make sense in your interface, but not inside another control. Then, maybe, the use can click on checkboxes to tag records to be saved, no? Then when everything is all set to export, you have to pick out the record details and write them to a file yourself. You'll have to supply the code for import and export. Possibly create another DataSet using the checkmarked record to fill the table, then serializing the data out to a file. It's entirely up to you what kind of file you want to use and how you want that data to look in it. That will determine how you write the file out.
RageInTheMachine9532
|
|
|
|
|
i posted before asking how to accomplish this and was replied to, but what they said didn't seem to work (else i was being more thick than usual! :p).
this is what i need to do:
in an MDI environment, have a variable in FormParent called MyVar. i need to set this within that form (a task i do understand!) and then in my child generated from FormChildTemplate check the variable and set it as something else, then to be able to use it again in FormParent.
anyone get the idea and can tell me?
thanks in advance,
surgeproof.
----------------------------------------------
looking for hosting? ithium is good.
|
|
|
|
|
Either pass a reference to the parent form in the constructor (or a property) of the parent form's Type, or cast the child's MdiParent to the actual form's Type and access the public or internal property or field. If you just try to access it from MdiParent , it won't work because that returns a Form , which doesn't declare your field or property. That's what you cast it, since your parent form is a derivative of Form .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks. you couldn't explain that a little bit more please could you? do you mean when initialising my variable putting something like (FormParent) on the end? or would i try FormParent.MyVar beacuse this doesn't seem to work.
thanks.
-------------------------------------------------------
looking for hosting? ithium is good.
|
|
|
|
|
It's a simple matter of access. First, your field (not variable, which is a temporary variable declared in a method) or property (properties are recommended to use from other classes) must be either public or internal (for classes within a single assembly), or protected if using a derived class (which you probably wouldn't). Then you must make sure the child form can access that field or property either by casting MdiParent or passing a reference to your parent form (FormParent I'm assuming) to your child form. An example of the former is:
public class MyChildForm : Form
{
protected void ShowParentFormsProperty()
{
FormParent form = (FormParent)MdiParent;
if (form != null) MessageBox.Show(form.MyProperty);
}
} The latter way:
public class MyChildForm : Form
{
private FormParent parent;
public MyChildForm(FormParent parent)
{
this.parent = parent;
}
protected void ShowParentFormsProperty()
{
if (parent != null) MessageBox.Show(parent.MyProperty);
}
} In both examples, your FormParent may look like this:
public class FormParent : Form
{
public FormParent()
{
MyChildForm form = new MyChildForm(this);
AddOwnedForm(form);
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks, i'll try that and say how i got on soon.
surgeproof
-------------------------------------------------------
looking for hosting?ithium is good.
|
|
|
|
|
Does anyone know how to convert a .NET bitmap to a DIB? I have tried to port code from C++ without success, so I would appreciate any help. Thanks alot
|
|
|
|
|
isn't a DIB just the method bitmaps use to store? and do you want to convert in realtime or just with an application? if it's the latter you might want to use something like PainShopPro or AdobePhotoShop etc. but if it's in realtime i'm not sure. wouldn't you use the System.Drawing.Imaging controls?
surgeproof.
-----------------------------------------------
looking for hosting?ithium is good.
|
|
|
|
|
Hi all!
I'm a bit new to C#. I am developing a Windows application. I've spent a few weeks designing this application. I want the windowsapplication to be the client in my server/client system. I want to connect the server to a database and bring back the data from the dB to the client. As I said, I'm new to C#, and not a very experienced programmer. Where and how do I start implementing this system?
Grateful for all the help I can get!
/Martin
|
|
|
|
|
The first thing to do is to read through the topics in the .NET Framework SDK[^] (also installed on your machine as part of the .NET Framework SDK and VS.NET). Specifically, take a look at Accessing Data with ADO.NET[^]. CodeProject also contains a wealth of information, but familiarize yourself with the basics of .NET development first (i.e., what an assembly is, what managed code is, how C# relations to the .NET Framework and managed code, etc.).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a class with a property which I want to bind to the selected value of a Listbox.
I use the databindings property of the listbox, and the binding work fine...when you select a different value from the listbox, it updates the objects property. The problem is that when you lose focus on the listbox, the selected Index gets reset to -1...Any thoughts??
Gregg R
|
|
|
|
|
Are you using ListBox or ListView?
For ListView the default property for HideSelection is true, so when it looses focus, it seems like the selection is gone. If you set that to false, the listview will show selection after focus is lost.
If it's ListBox, it shouldn't set the selected index to -1, unless you're doing it programmatically somewhere in your code.
|
|
|
|
|
I am using Listbox. No, I am not setting the index back to -1...Im just so confused...
I change the binding to a text box and it works just fine...
Regards
G
|
|
|
|
|
OK...Heres the situation:
I set the ValueProperty of the listbox to a int property, whereas the property on the object was string...when the listbox updated the object, it casted int to string, but when the object tried to set the ValueProperty it couldn't due to the type conversion.
Probelm solved.
Thanks anyway
GR
|
|
|
|
|
There's nothing exposed in the class nor available through reflection. RegQueryValueEx is used internally to get the value.
So, you'll have to P/Invoke RegQueryValueEx and get the type for yourself. If you need it; otherwise, try calling GetType from the return value of RegistryKey.Getvalue and make assertions based on that. If you get back System.String , you know it was either REG_SZ , REG_MULTI_SZ , or REG_EXPAND_SZ (in the latter case, search for occurances of '%' to determine exactly, and call Environment.ExpandEnvironmentVariables if you want to expand the string). If you get System.Int32 , you know it was a REG_DWORD . For System.Int64 , assume REG_QWORD . If you bet a System.Array , you can either double-check or assume a byte[] array and know that the registry type was REG_BINARY .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the answer... but
when I do GetType() I have the type of the object while I debug it (I can see which type it is). But how can I check the type programmatically?
of course these following lines are wrongly written, but how can I do correctly these tests in order to correctly cast the object given by RegistryKey.GetValue()?
[CODE]
if (ob.GetType() == System.String)
{ // proceed string }
else if (ob.GetType() == ...)
{ // proceed other objects }
[/CODE]
How can I write such a test?
Thanks.
|
|
|
|
|
Similar to how you did it. Familiarity with such type-checking code is often necessary:
object value = reg.GetValue("SomeName");
if (value is string)
{
}
else if (value.GetType() == typeof(int))
{
}
else if (value.GetType() == typeof(long))
{
}
else if (value is Array)
{
}
else throw new InvalidOperationException("Unknown registry key type."); I used two different ways to determine type. There's the is keyword which actually translates to the simple, one-line IL instruction isinst , but you can only use a reference type (which Int32 and Int64 aren't) as the second operand. You can also use obj.GetType() == typeof(type) , specifying the type at design-time. typeof is a keyword that gets the type and hardcodes it in the generates instructions. If you want to compare two unknown types at runtime, use objA.GetType() == objB.GetType() or the same with the Equals (instead of == ) method (the override for Type.Equals compares types, which includes the assembly name information - not just the namespace and class/struct/interface/enum name).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
aaah... ok I see... That's it. That's what I was searching for.
Thanks a lot!
so, for testing an System.Array object, I have to use the "is" keyword or the typeof() function? I saw that REG_MULTI_SZ are considered as System.Array in .NET... I guess this is an array of "String"...
|
|
|
|
|
You're right - I wasn't thinking. A REG_MULTI_SZ would be an array. In that case, first do a simple check for the System.Array type, then you could get the first element and check it's type. It'll either be a String or Byte so use typeof since Byte is a value type.
Using is is slightly faster (1 or 2 instructions as opposed to 2 or 4 - you make the call how important that is) than using typeof , but can only be used when the second operand is a reference type. Below is an IL comparison of using each(str is a variable referencing a String ):
ldloc.0
isinst [mscorlib]System.String
ldloc.0
callvirt instance class [mscorlib]System.Type [mscorlib]System.Object::GetType()
ldtoken [mscorlib]System.String
call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(
valuetype [mscorlib]System.RuntimeHandle)
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
You know this inverted shortcut icon on top of each page in VS.NET help; you're supposed to click on it, and it drops down a yellow menu that makes you filter the page by C#, VB or JScript. Well, I have to do this for each page. I want it to stick. Can I do that?
Thanks.
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
It is supposed to persist for the class reference, but often does not persist for technical articles where such a feature is enabled. This just has to do with the information stored in the MSHelp metadata in each page and any cookies that are created (or aren't created, which is the problem with not being persisted).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi,
i want to redirect a certain window output into my application???????
thanx
|
|
|
|
|
First off, is this a WinForm or WebForm environment? If it's web, are you using frames within the same "window"? Or, are you wanting 2+ separate windows to talk to each other?
This is a start. Let me know.
Michael Flanakin
Web Log
|
|
|
|