Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6241431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:46:02+00:00 2026-05-24T11:46:02+00:00

I have a following interface: public interface IDataAccessor { IList GetAllRecords(); IFormEditor ShowAddEditForm(); }

  • 0

I have a following interface:

public interface IDataAccessor
    {
        IList GetAllRecords();
        IFormEditor ShowAddEditForm();


    }

and class which inheritance this interface:

 public class LanguageDataAccessor : IDataAccessor
    {

        public void SaveLanguage(Languages language)
        {
            LanguagesDAO languages = new LanguagesDAO();
            languages.Save(language);
        }
    // other methods...
}

In user control I have the following code:

public partial class ucDisplayDictionary : UserControl
    {
        public Type DictionaryName { get; set; }
        public IDataAccessor DataAccessor { get; set; } 

public ucDisplayDictionary(IDataAccessor accessor)
            : this()
        {
            DataAccessor = accessor;
            DictionaryName = accessor.GetType();
        }

private void btnEditRecord_Click(object sender, EventArgs e)
         {
             if (dgvDisplayDictionary.CurrentRow != null)
             {
                 var frmEdit = DataAccessor.ShowAddEditForm();

                 frmEdit.SetValue(dgvDisplayDictionary.CurrentRow.DataBoundItem);                    

                 if (frmEdit.GetForm().ShowDialog() == DialogResult.OK)
                 {
                     dgvDisplayDictionary.DataSource = null;
                     dgvDisplayDictionary.DataSource = ((LanguageDataAccessor)DataAccessor).Collection; // *                           
                 }
             }    
         }

In the string (*) I want to write something like that:

dgvDisplayDictionary.DataSource = ((DictionaryName)DataAccessor).Collection;

because this user control is common for other DataAccessor,

How can I do this?
Thanks and sorry for my english.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:46:04+00:00Added an answer on May 24, 2026 at 11:46 am

    If all your IDataAccessor implementations have a Collection property, you should put that property in IDataAccessor – then you don’t need a cast at all.

    If your Collection property is strongly typed, you might want something like:

    public interface IDataAccessor
    {
        IList GetAllRecords();
        IFormEditor ShowAddEditForm();
        IList Collection { get; }
    }
    
    public interface IDataAccessor<T> : IDataAccessor
    {
        new IList<T> Collection { get; }
    }
    

    (In the same way as IEnumerator has the non-generic Current, and the generic IEnumerator<T> has the generic property.)

    That way anything which needs the collection in a strongly typed way can use IDataAccessor<T> but you don’t need to make your ucDisplayDictionary class generic. (I suggest you rename that to follow .NET conventions by the way – it looks ghastly at the moment.)

    It’s possible that your IDataAccessor.GetAllRecords() method already does what you want of course, and you only need to change your code to:

     dgvDisplayDictionary.DataSource = DataAccessor.GetAllRecords();
    

    (You don’t need to set the DataSource to null first, by the way.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider I have the following interface: public interface A { public void b(); }
I have the following classes public interface InterfaceBase { } public class ImplementA:InterfaceBase {
I have the following code: import com.apple.dnssd.*; public interface IServiceAnnouncer { public void registerService();
Let's say that I have the following interface: public interface IMyService { void SimpleMethod(int
I have this following interface : public interface FruitDetails { public String getFruitName(); }
I have the following interface: public interface ILogger { void Debug(string message, params object[]
Assuming that I have the following interface and class: public interface IFooRepo : IDisposable
I have the following interface: public interface Iface { void Sample1(); void Sample1(bool value);
If I have the following Interface structure; public interface IPaymentTypeBase { void PayNow(); double
Hi have the following interface: public interface KeyValueStore { public void put(String key, byte[]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.