C# .NET - C# - Cast BindingSource to DataView

Asked By Aldo Liaks on 16-Jul-08 05:59 AM

I didn't get it my problem solved, so I am trying in another way, but need some help casting bindingSource to DataView.

Thanks in advance,

Aldo.

BindingSource bindingSource = new BindingSource();

bindingSource.DataSource = CreateDataTable("FieldsConfig", originalDataGridView);

 

// Bind DataGridView to BindingSource.

dgvPT.DataSource = bindingSource;

 

// Now I need to Sort the DataGridView by columns "Orientation" and "Position".

// How can I do it? I was trying… but getting cast exception

DataView dataView = dgvToSort.DataBindings[0].DataSource;

 

dataView.Sort = "Orientation, Position asc";

 

dgvToSort.DataSource = dataView;

 

solution : Binding Source

Sakshi a replied to Aldo Liaks on 16-Jul-08 07:52 AM

try this


   BindingSource m_CustomersBindingSource = new BindingSource();

DataRowView currentRowView = m_CustomersBindingSource.Current      as DataRowView;


   CustomersDataSet.CustomersRow custRow = currentRowView.Row
      as CustomersDataSet.CustomersRow;
   string company = custRow.CompanyName;
   string phoneNo = custRow.Phone;

SOLVED

Aldo Liaks replied to Sakshi a on 16-Jul-08 07:56 AM

Hi Umapathy,

Thanks for your help.

I solved it this way: http://www.eggheadcafe.com/community/aspnet/2/10044229/thanks-.aspx