Databinding to the correct Row
-
I have a small form that I spawn from another that acts as a way to edit a row of data from a typed DataTable. Within the load() method of the form, I execute this code.
mySource = new BindingSource(); mySource.DataSource = myManagerClient.VersionTable; uxcbFMonth.DataBindings.Add("SelectedValue", mySource, "FiscalMonth"); uxtextFYear.DataBindings.Add("Text", mySource, "FiscalYear"); uxtextName.DataBindings.Add("Text", mySource, "VersionName"); uxcbType.DataBindings.Add("SelectedValue", mySource, "Type");
That works just fine and the data is all bound correctly. The problem is that it defaults to the first row of data in the sorted bindingsource. I have a foreign key value for the datarow I want to display, and I know I need to use the BindingSource.Position property to properly set the position I want to edit, but I'm having problems correctly finding the value to pass. I tried using mySource.IndexOf(/*The DataRow using myManagerClient.VersionTable.Select()*/), that returned -1. I also tried to use mySource.Filter(), but that filters the data in the main form as well (since I'm using Form.Show() instead of Form.ShowDialog()), and visually, I think that will confuse the end-user. As far as I can tell at the moment, I'm going to have to manually pass through each row until I find the right one, but there really seems like there might be an easy way that I'm just missing. Any ideas? -
I have a small form that I spawn from another that acts as a way to edit a row of data from a typed DataTable. Within the load() method of the form, I execute this code.
mySource = new BindingSource(); mySource.DataSource = myManagerClient.VersionTable; uxcbFMonth.DataBindings.Add("SelectedValue", mySource, "FiscalMonth"); uxtextFYear.DataBindings.Add("Text", mySource, "FiscalYear"); uxtextName.DataBindings.Add("Text", mySource, "VersionName"); uxcbType.DataBindings.Add("SelectedValue", mySource, "Type");
That works just fine and the data is all bound correctly. The problem is that it defaults to the first row of data in the sorted bindingsource. I have a foreign key value for the datarow I want to display, and I know I need to use the BindingSource.Position property to properly set the position I want to edit, but I'm having problems correctly finding the value to pass. I tried using mySource.IndexOf(/*The DataRow using myManagerClient.VersionTable.Select()*/), that returned -1. I also tried to use mySource.Filter(), but that filters the data in the main form as well (since I'm using Form.Show() instead of Form.ShowDialog()), and visually, I think that will confuse the end-user. As far as I can tell at the moment, I'm going to have to manually pass through each row until I find the right one, but there really seems like there might be an easy way that I'm just missing. Any ideas?Found it, I needed to change the second line above to include .Select().