|
Joby,
I think I have a solution that is at least a little more elegant than your current...
Given your interfaces described above, I changed the TowerList to use Generics:
public class TowerList<T> : BindingList<T> where T: ITower
{
}
Then I created a Tower class which implements ITower. Because the Interface is simply a contract, the Tower class must implement each member. For the sake of testing, I just dumped in random values into the properties so something would show up on the grid:
public class Tower : ITower
{
#region ITower Members
private double _height;
public double Height { get { return _height; } }
#endregion
#region IModule Members
private string _partNumber;
private string _partDescription;
public string PartNumber { get { return _partNumber; } }
public string PartDescription { get { return this.Name + " for part #" + _partNumber; } }
#endregion
public String Name { get; set; }
public Tower()
{
Random rnd = new Random();
_height = rnd.NextDouble() * rnd.Next(400, 500);
_partNumber = "X" + rnd.Next().ToString() + rnd.Next().ToString();
}
Then in a form_load event I created a TowerList object like such:
TowerList<Tower> myTowers = new TowerList<Tower> {
new Tower { Name = "TowerX1" },
new Tower { Name = "TowerY2" }
};
I then set the .Datasource property of my DataGridView control and, voilà, all the inherited properties displayed correctly!
You could also define a Towers class as public class Towers : TowerList<tower></tower> if you wanted to add special behavior to Towers lists.
Unfortunately, I don't have an answer as to why the datagrid does not bind all the inherited properties when we do the code the way you described above (I was able to replicate the behavior, though...).
|
|
|
|
|
Hello. I have a DataGridView that is bound to a DataTable. If the user types in values for all the columns for the first row, then clicks into a column in the second row (empty), and then clicks back into the first row he just typed, then an empty row is added to the DataGridView. I'm guessing that somehow the AddRow function is being called when the user clicks in and out of the empty row. I don't want this to happen. A new row should only be added to the DataGridView if the user types in valid values for all the columns. Does anyone know how to fix this? Thanks.
Justin
|
|
|
|
|
Dear sir,
i am developping windows application in that i am using ftp / web client methods using threads to upload a file, to save a file. so whenever i ckick on the save button the file was saved. for saving the file it takes some time depend on the file size.now i want to cancel the saving process in middle by using the cancel click event.
similarly i have uploading file procedure also. when i click on upload a file then file has uploaded but i want to cancel the upload process in middle by clicking cancel button.
please help me.i have only one line code in cancel button i.e this.close(). this is to close the form. but i want to stop the process in middle also if i click on cancel button.
Regards,
Balaji.V
|
|
|
|
|
Well, it would help to see the code that you want to stop running. Also, you need to use threads, so your UI is responsive. If you do this, one inelegant solution is to kill the thread that is uploading.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
balaji_vbr wrote: using ftp / web client methods using threads to upload a file
If you are using the asynchronous method like UploadFileAsync() , I believe there is a CancelAsync method too which can cancel the operation.
|
|
|
|
|
I was hoping one of you clever people could me a hand...
I have a form with an array of class "myObject" that holds my data and I want to show the array in a ListBox control that will display the Name property. When the user clicks on an item in the list the details of that item are displayed in some TextBox controls. The user can now edit the data when they are done they click a button that will update the array and if needed the display name in the list. or even reflect changes straight into the array
How do I databind my object array like a database table? I've tried reading the MSDN on ListBox Control Overview (Windows Forms) but it isn't very clear/only talks about databases.
Not understanding this small area is really holding back my .NET work
I did find this[^] while I was looking but it only covers using a DataSet from a DB.
Dave Henry
-----------------------------------------
evil mastermind or genius benefactor?
NEVER trust the bunny...
modified on Sunday, July 6, 2008 4:15 PM
|
|
|
|
|
You probably will want to use Collection instead of array for binding to listbox.
1. For the display of object in the listbox, override ToString() to display the value that you want on the listbox.
2. Implement INotifyCollectionChanged and INotifyPropertyChanged.
|
|
|
|
|
I forgot to say that I'm using .NET 2.0
Also what do you mean a collection? something like List<myObject>> ?
I'm using the array object because I know that I can easily serialize the array to/from a file.
Dave Henry
-----------------------------------------
evil mastermind or genius benefactor?
NEVER trust the bunny...
|
|
|
|
|
Collection is in .NET since at least 1.1.
You can probably use List<t> for the same purpose though I have not tried that before.
CollectionBase[^]
|
|
|
|
|
either way I still don't know how to data bind the Array/List/Collection to my list box displaying the name property and allow edits from my TextBoxes
public class myObject
{
public string Name;
public string Company;
public string Title;
public string Phone;
}
In the form:-
private myObject[] bodList = new myObject[5]();
I want an GUI that looks like this[^], the same functionality just using my object and NOT a DB connection.
Dave Henry
-----------------------------------------
evil mastermind or genius benefactor?
NEVER trust the bunny...
|
|
|
|
|
Do you mean the databinding of the textboxes? There's no quick way to do that.
The right panel with a textbox is a form or custom control that has a public property of myObject.
1. In the setter, check for null, if null, disable all textbox and clear all text.
2. If not null, that means an object is already bound to the form/custom control. Clear all the databinding of textbox, then set the databinding of the textboxes to the properties of the new object, accordingly.
On the listbox end, when there's a selected index changed, get the selected object from the listbox, and set it to the form/custom control public property.
|
|
|
|
|
After a bit of searching I found This[^] which explained how to use a BindingSource object to bind together all the controls.
The only thing was in the article he adds each reference with the add method on BindingSource instead I just set the DataSource to my array.
Using this method to populate a listbox you get a list showing the object name until you set the DisplayMember to a property name. Also BindingSource only shows properties so my class of public fields didn't work I had to make them all private alter the name and add a public getter and setter with the names i was using elsewhere in my code. But now my textboxes are bound to the array and display whatever is selected in my listbox .
Job Done.
Dave Henry
-----------------------------------------
evil mastermind or genius benefactor?
NEVER trust the bunny...
|
|
|
|
|
In my project i want to implement sound recording what we have in windows xp so i want consume that.
Give me suggestion how to implement recording sound in .net any dll is avliable?
help me out
Ashok Nalam
|
|
|
|
|
Don't post in multiple forums, it's rude.
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
Hi,
I have to excute my own functionality while closing the windows form.
but its always firing formclosing event (I can not use formclosing event as I am using this to navigate to other forms)
Finally, Please help me to solve, how to excute functionality of MyOwn Button while closing using ControlBox's X Button
Thanks,
Prashanth
|
|
|
|
|
Call MyOwn Button's event handler in formclosing event.
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
Thanks for your help Mr.Giorgi Dalakishvili,
But that won't solve my Problem,
See, I am not using MDI.
I have Main Form which contains Exit,Form1 and few other buttons, and my functionality to close the application is written in exit button.
But when user clicks any other button say,Form1 to go Form1, Since The Main Forms Close event also calling at that time the Main Form too closing not my application(So all the threads and timers that I wrote in exit button are not ending)
I just want to know how to call my exit button functinality Only when user clicks ControlBox's X Button.
Thanks,For ur Time
Pashi
|
|
|
|
|
Your post is quite unclear but from what I guess that when you click Form1, your main form is closing. Why do you do that? Just show Form1.
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
Thanks Again For your reply,
say I am in Main Form Now.
After I click on Form1 Button of Main Form, Main Form's Closing event is calling and since the in the ControlBox 'X' Button is also calling Main Form's Closing event for Main form the application is closing.
So, I just want to know do I have any alternate so that, I can catch the form Closing Event
I mean whether the process is entering into form closing event by ControlBox's 'X' click or
while redirecting to any other form.
Hope you got my point now!
Thanks again for ur time
prashanth,
s/w Engineer,
Syfnosys.
|
|
|
|
|
Maybe a CloseReason property of a FormClosingEventArgs object which passed by a Closing event is what are you looking for.
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
The pages have been done with a 1280 x 1024 resolution. I am currently using it on a laptop having 1440 x 900, and unfortunately I can not reach the previous next button placed on the bottom of the page without scrolling down each time.
Is there any way, that i can set the properties of form such that it will make the form size as per windows pixel values.
|
|
|
|
|
The dock and anchor properties can be set to make a form resize itself cleanly.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
yes you r right that dock property is being use to resizing the control, but i m currently using the FORM not controls, my form is not getting resized accordingly and form is not having any dock property.
and i have made autosize property of form to grow and shrink.
can you guide me for this.
Thanks
|
|
|
|
|
Hi,
you can set your Form's Size at Load time using your monitor's Size; have a look at
either the Screen class or SystemInformation.PrimaryMonitorSize
|
|
|
|
|
I'm having intermitent problems with my winforms app since I added a System.IO.Ports.SerialPort object to receive strings from the serial port, then write those strings to the database.
I know that because of cross-threading exceptions, if I want to update any control on my form, I need to update it from that control's invoke method. I'm fine with that.
But what if I want to execute a method of an object that doesn't inherit from Windows.Forms.Control, and therefore doesn't have an Invoke method?
For example
DataAccessLayer dal;
IO.Ports.SerialPort port;
string portBuffer;
private void frmMain_Load(object sender, EventArgs e)
{
dal = new DataAccessLayer();
port = new IO.Ports.SerialPort();
}
void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
portBuffer += port.ReadExisting();
if (portBuffer.Contains("OK"))
dal.InsertStringIntoDatabase(portBuffer);
}
Does the 'dal' object run on a different thread from the 'port' object? If so, must I write a custom BeginInvoke, Invoke method for the 'dal' object. The dal object does not inherit from Control.
Thanks
|
|
|
|