Domanda

I am trying to debug the following line of code

binding.DataSource = this.bindingSource.DataSource;

and want to find out more information about binding.DataSource

In the immediate window the query ? binding.DataSource returns

Count = 1
[0]: {Contact Events}

I want to cast the binding.DataSource to something I can query with intellisense? What should I cast it to ?

[Update] The binding source was created as follows;

public BindingSource GetEventTypesBindingSource()
    {
        try
        {
          DbSet<ContactEventType> dset = base.Context.ContactEventTypes;
          IOrderedQueryable<ContactEventType> qry = dset.Where(p => p.Id > 0).OrderBy(x => x.Description);
            qry.Load();
            var bindingSource = new BindingSource();
            bindingSource.DataSource = dset.Local.ToBindingList();
            return bindingSource;
        }
        catch (Exception ex)
        {
            HandleException.Show(ex);
        }
        return null;
    }

[Update] I tried the following in the debugger

? (List<ContactEvent>) binding.DataSource.GetType() 

but get

The type or namespace name 'List' is not valid in this scope
È stato utile?

Soluzione

It's probably List<ContactEvent>, but you can find out using the debugger and/or reflection.

If you view the variable in the Watch window of the debugger, it will show the type of the data. If you call GetType on the datasource it will return the type of the object (you can do this in the debugger too, and examine the resulting type there).

Altri suggerimenti

first its not related to answer but you dont have to use datasource in this case (you dont use datamember property). you can just bind it to the collection directly. the type of collection could be a custom bindinglist implementation from entity framework assembly. maybe you dont see its name because its not public, but casting to IEnumerable should work. if i remember correctly that custom implementation derive from BindingList so BindingList is also ok.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top