Click here to Skip to main content
15,884,177 members
Home / Discussions / C#
   

C#

 
GeneralRe: c# OPCgroup.SyncWrite vs. Float type Pin
Roberto64_Ge19-Feb-21 0:24
Roberto64_Ge19-Feb-21 0:24 
GeneralRe: c# OPCgroup.SyncWrite vs. Float type Pin
OriginalGriff19-Feb-21 0:55
mveOriginalGriff19-Feb-21 0:55 
GeneralRe: c# OPCgroup.SyncWrite vs. Float type Pin
Roberto64_Ge19-Feb-21 1:41
Roberto64_Ge19-Feb-21 1:41 
GeneralRe: c# OPCgroup.SyncWrite vs. Float type Pin
OriginalGriff19-Feb-21 1:58
mveOriginalGriff19-Feb-21 1:58 
GeneralRe: c# OPCgroup.SyncWrite vs. Float type Pin
Roberto64_Ge19-Feb-21 2:28
Roberto64_Ge19-Feb-21 2:28 
GeneralRe: c# OPCgroup.SyncWrite vs. Float type Pin
Roberto64_Ge19-Feb-21 8:27
Roberto64_Ge19-Feb-21 8:27 
GeneralRe: c# OPCgroup.SyncWrite vs. Float type Pin
Roberto64_Ge23-Feb-21 0:53
Roberto64_Ge23-Feb-21 0:53 
QuestionWinforms Usercontrol Databinding question Pin
Member 1501196518-Feb-21 5:20
Member 1501196518-Feb-21 5:20 
I have a databinding issue with a numericupdown control bound to a bindinglist of objects. The updown control is located on a usercontrol. The controls can be loaded with values from a file located in a defaults xml file. The databinding works as it should upon loading the defaults file the first time. If during the session, I want to reload the defaults the databinding is lost. I can see that the values are loaded in correctly, but the numericupdn doesn't change value. here's a simplified version of my code to help explain.

Object class:

public class Garage : 
{

		
		



public BindingList<DrawerData> Drawer = new BindingList<DrawerData>
		{
			new DrawerData(),
			new DrawerData()
			
		};
}
	
public class DrawerData : INotifyPropertyChanged
{
	private decimal _NumberOfTools;
	public event PropertyChangedEventHandler PropertyChanged;

	public decimal NumberOfTools
		{
			get { return _NumberOfTools; }
			set {
				if (_NumberOfTools != value)
				{
					_NumberOfTools = value;

					OnPropertyChanged("NumberOfTools");
				}
			}
		}

	public event PropertyChangedEventHandler PropertyChanged;
		public void OnPropertyChanged([CallerMemberName] string PropertyName = "")
		{
			
			PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(PropertyName));
			
		}

}


Usercontrol class:

public partial class UcDrawer : UserControl, INotifyPropertyChanged
{

	private readonly Garage _Garage;
	private readonly int Drw
	BindingSource bindingSource = new BindingSource();

	public event PropertyChangedEventHandler PropertyChanged;

	public UcDrawer(int drw,Garage garage)
		{
			_Garage = garage;
			Drw = drw;

			bindingSource.DataSource = _Garage.Drawer[Drw];
			
		}

	private void UcDrawer_Load(object sender, EventArgs e)
		{
			UpDnSettingsNumberOfTools.DataBindings.Add(new Binding("Value", bindingSource, "NumberOfTools", true, DataSourceUpdateMode.OnPropertyChanged));
			
		}

}


Form where usercontrol is used (it's loaded into tabpages in a tabcontrolon the form):

public partial class FrmGarage : Form
	{
		private readonly int Drw;
		private readonly Garage _Garage;

		public FrmGarage(int drw, Garage garage )
		{
			InitializeComponent();
			Drw = drw;
			_Garage = garage;
		}

		private void FrmGarage_Load(object sender, EventArgs e)
		{
			for (int i = 0; i < ch; i++)
			{
				AddTab(i + 1);
			}
		}

		private void AddTab(int ChNum)
		{
			UcDrawer ucDrawer = new UcDrawer(Drw, _Garage) { Dock = DockStyle.Fill };
			TabPage myTabPage = new TabPage();
			myTabPage.Controls.Add(ucDrawer);
			GarageTabControl.TabPages.Add(myTabPage);

			myTabPage.Name = "Drawer" + Drw;
			myTabPage.Text = "Drawer " + Drw;
		}

		
	}
}


Main form (has buttons on a side list that load different forms into a panel, i'll only include the garage one for simplicity)

public partial class Form1 : Form
	{
		public Garage garage;
		readonly private FrmGarage FrmGarage_vrb;
		private Form ActiveMainForm = null;

		public Form1()
		{
			InitializeComponent();
			garage = new Garage();
			

			FrmGarage_vrb = new FrmGarage(2, garage)    { Dock = DockStyle.Fill, TopLevel = false, TopMost = true };
		}
		

		//Form loader code when one of the side buttons is clicked

		private void MainButtonListClickAction(Button buttonClicked, Form formActivated)
			{
				pnlNav.Height = buttonClicked.Height;
				pnlNav.Top = buttonClicked.Top;
				this.pnlFormLoader.Controls.Clear();
				this.pnlFormLoader.Controls.Add(formActivated);
				formActivated.Show();
				ActiveMainForm = formActivated;
			}


		public void BtnOverride_Click(object sender, EventArgs e)
			{
				MainButtonListClickAction(BtnGarage, FrmGarage);
			}


		//When the New button is pressed,  a defaults file is loaded

		private void BtnMainNew_Click(object sender, EventArgs e)
		{
			

			XmlSerializer serializer = new XmlSerializer(typeof(BindingList<DrawerData>));
			XmlReader reader = XmlReader.Create("defaults.xml");
			garage.Drawer = (BindingList<DrawerData>)serializer.Deserialize(reader);
			
			reader.Close();
			
		
		}

AnswerRe: Winforms Usercontrol Databinding question Pin
Gerry Schmitz18-Feb-21 7:38
mveGerry Schmitz18-Feb-21 7:38 
GeneralRe: Winforms Usercontrol Databinding question Pin
Member 1501196518-Feb-21 7:47
Member 1501196518-Feb-21 7:47 
GeneralRe: Winforms Usercontrol Databinding question Pin
Gerry Schmitz18-Feb-21 8:07
mveGerry Schmitz18-Feb-21 8:07 
QuestionArticle "tip/trick "Converting Enum member names and values in C#"" Pin
Сергій Ярошко16-Feb-21 22:46
professionalСергій Ярошко16-Feb-21 22:46 
AnswerRe: Article "tip/trick "Converting Enum member names and values in C#"" Pin
PIEBALDconsult17-Feb-21 3:17
mvePIEBALDconsult17-Feb-21 3:17 
GeneralRe: Article "tip/trick "Converting Enum member names and values in C#"" Pin
Сергій Ярошко17-Feb-21 4:13
professionalСергій Ярошко17-Feb-21 4:13 
GeneralRe: Article "tip/trick "Converting Enum member names and values in C#"" Pin
Richard Deeming17-Feb-21 4:31
mveRichard Deeming17-Feb-21 4:31 
GeneralRe: Article "tip/trick "Converting Enum member names and values in C#"" Pin
PIEBALDconsult17-Feb-21 5:19
mvePIEBALDconsult17-Feb-21 5:19 
QuestionHow C# handles binary files? Pin
Member 1477325816-Feb-21 21:59
Member 1477325816-Feb-21 21:59 
AnswerRe: How C# handles binary files? Pin
Richard MacCutchan16-Feb-21 22:11
mveRichard MacCutchan16-Feb-21 22:11 
AnswerRe: How C# handles binary files? Pin
OriginalGriff16-Feb-21 22:39
mveOriginalGriff16-Feb-21 22:39 
AnswerRe: How C# handles binary files? Pin
Gerry Schmitz17-Feb-21 6:00
mveGerry Schmitz17-Feb-21 6:00 
QuestionC#, loop statement Pin
Jennalyn Nayoyos15-Feb-21 2:57
Jennalyn Nayoyos15-Feb-21 2:57 
AnswerRe: C#, loop statement Pin
OriginalGriff15-Feb-21 3:16
mveOriginalGriff15-Feb-21 3:16 
AnswerRe: C#, loop statement Pin
Richard MacCutchan15-Feb-21 4:53
mveRichard MacCutchan15-Feb-21 4:53 
AnswerRe: C#, loop statement Pin
Gerry Schmitz15-Feb-21 6:10
mveGerry Schmitz15-Feb-21 6:10 
QuestionRe: C#, loop statement Pin
Kenneth Haugland15-Feb-21 19:42
mvaKenneth Haugland15-Feb-21 19:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.