Category: winforms

Feb 20 2014

What is the best way to create "abstract" class members when declaring the class as abstract is not an option?

        <p>There is a class that I want to create as abstract but I can't because that class's base class is ActiveReports and as soon as I make it abstract the sub-reports are no longer designable.  (Interestingly the base class itself IS designable but not it's children).</p>
I know that I cannot declare class members as abstract without first declaring the class as abstract. In this case what is the NEXT BEST way to do this. At this point I made the members virtual and added comments to each one. Where it made sense I also declared a member as protected rather than public. But is there some other best way that would REQUIRE that these members be overridden at compile-time rather than run-time? If you were in this situation how would you do it?
Feb 20 2014

What is the best way to create "abstract" class members when declaring the class as abstract is not an option?

There is a class that I want to create as abstract but I can't because that class's base class is ActiveReports and as soon as I make it abstract the sub-reports are no longer designable. (Interestingly the base class itself IS designable but not it's children). I know that I cannot declare class members as abstract without first declaring the class as abstract. In this case what is the NEXT BEST way to do this. At this point I made the members virtual and added comments to each one. Where it made sense I also declared a member as protected rather than public. But is there some other best way that would REQUIRE that these members be overridden at compile-time rather than run-time? If you were in this situation how would you do it? EDIT Let me explain further. I can create a class (lets call it MyReportsBase) that inherits from ActiveReports. (I do that using add new and choose the ActiveReports type) Then ActiveReports provides a property of the report object in MyReportsBase (in design time properties) called MasterClass. Once I set that property to true then I can then create new reports and inherit from MyReportsBase instead of directly from ActiveReports. (The way you do that is by create add new ActiveReports but then edit the code in the code-behind to inherit from MyReportsBase instead of ActiveReports). That is all well and good and it all works perfectly well. However, my requirement is that MyUpwardBase would HAVE to be inherited (declared abstract with a few abstract members). And I CAN go in the code-behind and set the abstract modifier on the base class. And even then I can design MyReportsBase. However, at that point, all of the reports that I inherited from MyReportsBase are no longer designable. Attempting to open the derived reports in the designer throws an error about how the designer cannot open the base class because it is declared as abstract. All of this is to just clarify the question. Right now the Interface suggestion is making the most sense to me. EDIT 2
An Interface doesn't really do it for me either for this reason. The base classes "abtract-but-aren't-abstract" members HAVE To be present in my base classes because I have virtual and public members that depend on them. And in my case, because I cannot declare the class as abstract, I have to have an implementation for those members. As soon as I provide an implementation for those members then all of my inheriting classes ALSO have the implementation and the Interface doesn't complain at compile time. I thought by removing the virtual modifier from those members that the compiler would require them but it did not behave that way. I am beginning to think that my solution (document the members well) is the best solution.
Dec 04 2013

How do you get CSLA 3.02 BusinessListBase ListChanged event to identify the child object whose OnPropertyChanged triggered the event?

        <p>I have a project that is using CSLA 3.0.2.</p>

I have a BusinessListBase collection object that has child items that have an IsDefault property.

When a child object has its IsDefault property set to true, I want to set the other child members IsDefault property to false.

I am calling the OnPropertyChanged("IsDefault") in the child setter and I have that raising the collections ListChanged event. However, the sender of the event is the Collection object, not the child object that raised the event. Nor is the child item in the ListChangedEventArgs (e).

How do I get a reference to the specific child instance that raised the event?

Or should I be doing this some other way?

Any help is appreciated.

Dec 04 2013

How do you get CSLA 3.02 BusinessListBase ListChanged event to identify the child object whose OnPropertyChanged triggered the event?

        <p>I have a project that is using CSLA 3.0.2.</p>

I have a BusinessListBase collection object that has child items that have an IsDefault property.

When a child object has its IsDefault property set to true, I want to set the other child members IsDefault property to false.

I am calling the OnPropertyChanged("IsDefault") in the child setter and I have that raising the collections ListChanged event. However, the sender of the event is the Collection object, not the child object that raised the event. Nor is the child item in the ListChangedEventArgs (e).

How do I get a reference to the specific child instance that raised the event?

Or should I be doing this some other way?

Any help is appreciated.

Dec 04 2013

How do you get CSLA 3.02 BusinessListBase ListChanged event to identify the child object whose OnPropertyChanged triggered the event?

        <p>I have a project that is using CSLA 3.0.2.</p>
I have a BusinessListBase collection object that has child items that have an IsDefault property. When a child object has its IsDefault property set to true, I want to set the other child members IsDefault property to false. I am calling the OnPropertyChanged("IsDefault") in the child setter and I have that raising the collections ListChanged event. However, the sender of the event is the Collection object, not the child object that raised the event. Nor is the child item in the ListChangedEventArgs (e). How do I get a reference to the specific child instance that raised the event? Or should I be doing this some other way? Like getting a reference to the parent in the child setter and doing it there? Any help is appreciated.
Jan 19 2012

How do I get .NET WinForms components to use a SET timezone instead of clients time zone?

I was not looking forward to describing this problem until I found another forum web site with the EXACT SAME question I need answered (but with no answer.) So with credit to this guy here is my question...

We have a large Windows .Net application (winform executable) that gets installed on the client's desktop. This application calls web services on a server in a different timezone. Virtually all date oriented components detect the timezone difference and automatically adjust the datetime values (returned in dataSets generated by SQL queries), which is generally desirable in most applications but causing problems with accounting related applications that are "date" not "datetime" oriented. We are only interested in the "date" portion. However, a date of 1/1/2003 GMT-5 is automatically converted to 12/31/2002 11:00 GMT-6 on the client. Rather than going through all of the code and extracting the UniversalTime to get back to 1/1/2003 for visual purposes we would like to simply "fake" the timezone for the client-side executable by making it think it's in the same timezone as the server.

Question: Can we set the TimeZone programmatically for the currently running instance only, rather than the global setting?

I really don't have much to add because it is our EXACT issue. In our case we have ActiveReports that are fetching remote SQL data into a datasets and then binding the report to the dataset. So, for example, birthdays are wrong because we are storing the Date for them and X hours are subtracting for the date in the western time zones? So the birthdates are off by minus 1.

Any thoughts?

Thanks!

Seth

Jan 19 2012

How do I get .NET WinForms components to use a SET timezone instead of clients time zone?

        <p>I was not looking forward to describing this problem until I found another forum web site with the EXACT SAME question I need answered (but with no answer.)  So with credit to <a href="http://www.hightechtalks.com/dotnet-framework-winforms/how-set-timezone-runtime-single-213152.html" rel="nofollow">this guy</a> here is my question...  </p>
We have a large Windows .Net application (winform executable) that gets installed on the client's desktop. This application calls web services on a server in a different timezone. Virtually all date oriented components detect the timezone difference and automatically adjust the datetime values (returned in dataSets generated by SQL queries), which is generally desirable in most applications but causing problems with accounting related applications that are "date" not "datetime" oriented. We are only interested in the "date" portion. However, a date of 1/1/2003 GMT-5 is automatically converted to 12/31/2002 11:00 GMT-6 on the client. Rather than going through all of the code and extracting the UniversalTime to get back to 1/1/2003 for visual purposes we would like to simply "fake" the timezone for the client-side executable by making it think it's in the same timezone as the server. Question: Can we set the TimeZone programmatically for the currently running instance only, rather than the global setting?
I really don't have much to add because it is our EXACT issue. In our case we have ActiveReports that are fetching remote SQL data into a datasets and then binding the report to the dataset. So, for example, birthdays are wrong because we are storing the Date for them and X hours are subtracting for the date in the western time zones? So the birthdates are off by minus 1. Any thoughts? Thanks! Seth
Jan 05 2012

How do I create a global exception handler for winforms app that is making asyncronous WebClient calls

I have a winforms app that is making asyncronous WebClient calls with a callback procedures as follows...

using (var wc = new WebClient())
{
    wc.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadCompleted);
    wc.DownloadProgressChanged+=new DownloadProgressChangedEventHandler(DownloadProgressCallback);
    //other stuff
    wc.DownloadFileAsync(uri, fullLocalPath);
}

I want to create a global exception handler so I have defined an application event for it...

[STAThread]
static void Main()
{
    Application.ThreadException += new ThreadExceptionEventHandler(ApplicationThreadException);
    //other stuff
    Application.Exit();

}

private static void ApplicationThreadException(object sender, ThreadExceptionEventArgs e)
{
    // Do logging or whatever here

    Application.Exit();
}

I believe that I am correct that application errors that are raised by the Callback event will not be caught by the Application.ThreadException? So what is the best way of insuring that the callback exceptions are handled?

I have seen on other SO posts that you can also create a handler for AppDomain.CurrentDomain.UnhandledException. Is that the best way to handle the callback exceptions?

I am just looking for best practices when using asyncronous callbacks in a winforms app.

EDIT

Nicholas...thanks for your answer. So can I put the whole callback into a try catch and then do a throw in the catch. Or do I have to explicitly check the AsyncCompletedEventArgs.error property for a non-null value.

If it IS non-null...can you tell me how to cause the callback error to bubble up to my global exception handler?

I think I would do it like this...

private void DownloadCompleted(object sender, AsyncCompletedEventArgs e)
{

    if (e.Error != null)
    {
        throw e.Error;
    }

    if (DownloadHasCompleted == null) return;
    File.Copy(this.RemoteIniFilePath, this.CurrentIniFilePath, true);
    DownloadHasCompleted(this, e);
}

Seth

Jan 27 2011

For a .NET winforms datagridview I would like a combobox column to have a different set of values for each row

I have a DataGridView that I am binding to a POCO. I have the databinding working fine. However, I have added a combobox column that I want to be different for each row. Specifically, I have a grid of purchased items, some of which have sizes (like Adult XL, Adult L) and other items are not sized (like Car Magnet.)

So essentially what I want to change is the DATA SOURCE for a combobox column in the data grid. Can that be done?

What event can I hook into that would allow me to change properties of certain columns FOR EACH ROW? An acceptable alternative is to change a property when the user clicks or tabs into the row. What event is that?

Seth

EDIT
I need more help with this question. With Triduses help I am SO close but I need a bit more information.

First, per the question, is the CellFormatting event really the best/only event for changing the DataSource for a combo box column. I ask because I am doing something rather resource/data intensive, not merely formatting the cell.

Second, the cellformatting event is being called just by having the mouse hover over the cell. I tried to set the FormattingApplied property inside my if-block and then I check for it in the if- test but that is returning a weird error message. My ideal situation is that I would apply change the data source for the combo box once for each row and then be done with it.

Finally, in order to set the data source of the combobox colunm I have to be able to cast the Cell inside my if block to a type of DataGridViewComboBoxColumn so that I can fill it with rows or set the datasource or something. Here is the code I have right now.

Private Sub ProductsDataGrid_CellFormatting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles ProductsDataGrid.CellFormatting

    If e.ColumnIndex = ProductsDataGrid.Columns("SizeDGColumn").Index Then ' AndAlso Not e.FormattingApplied Then
        Dim product As LeagueOrderProductInfo = DirectCast(ProductsDataGrid.Rows(e.RowIndex).DataBoundItem, LeagueOrderProductInfo)
        Dim sizes As LeagueOrderProductSizeList = product.ProductSizes
        sizes.RemoveSizeFromList(_parentOrderDetail.SizeID)

        'WHAT DO I DO HERE TO FILL THE COMBOBOX COLUMN WITH THE sizes collection.

    End If

End Sub

Please help. I am completely stuck and this task item should have taken an hour and I am 4+ hours in now. BTW, I am also open to resolving this by taking a completely different direction with it (as long as I can be done quickly.)

Seth

Jan 27 2011

How do you create Winform user control that supports multiple items like a listbox

I think I understand the basics of create winforms user control. I can do Add New and select user control and that will give me a design surface and designer file and code-behind file etc. And then I could change it to inherit from something other than UserControl (like listbox or text box).

The thing that is different for me this time is the user control needs to be a list control (like a list box) that can be data-bound and with two data-bindable controls in it (two combo boxes).

I am not sure where to start? Can anybody reference a document or some obvious bit in the tooling that I am missing that will make it quick and easy? Any approaches I can take like extending an existing control. Any gotchas I need to be aware of?

Thanks.

Seth

EDIT
I have decided to take a different approach. I am leaving the question up, though. This is clearly difficulty than I had guessed. WPF is not an option for me unfortunately. Just gonna use a data grid.