Search code examples
c#winformscastingdatarowview

Why the Combox.SelectedItem as DataRowView is not casting?


I have a combox and trying to cast its SelectedItem property to DataRowView like this

    DataRowView drFromWareHouse = cmbFromWareHouse.SelectedItem as DataRowView;

but it is showing redline and when I move the Cursor on it. It shows me cmbFromWareHouse does not exist in the current context. Kindly guide me what's going wrong with it?


Solution

  • The variable "cmbFromWareHouse" is out of scope. You can't access it from where you are trying to access it from