Form controls data binding sequence
-
I'm developing a databound desktop application. On one particular form, I have two list controls -- call them list A and list B. The choices of list B are directly dependent on the selection made in list A. When creating a new record, this is all fine. I make a selection in list A, and the SelectionChanged event triggers a repopulation of the options in list B. The problem comes in on loading a record from a database. Even though I can see the related fields for the A and B selections both have legit data, a list B selection is not being made at data-binding time. Step tracing shows me that .NET is attempting to bind the list B selection first. Since no A selection has been made at that point, the data source for list B is null, and so no selection is made. These "lists" are custom controls, so I could kludge it and put in a "memorized" value that retroactively makes the selection once the control's data source is not null. But that seems like really bad practice. Is there a way to set the sequence of individual control data binding at the form level?
-
I'm developing a databound desktop application. On one particular form, I have two list controls -- call them list A and list B. The choices of list B are directly dependent on the selection made in list A. When creating a new record, this is all fine. I make a selection in list A, and the SelectionChanged event triggers a repopulation of the options in list B. The problem comes in on loading a record from a database. Even though I can see the related fields for the A and B selections both have legit data, a list B selection is not being made at data-binding time. Step tracing shows me that .NET is attempting to bind the list B selection first. Since no A selection has been made at that point, the data source for list B is null, and so no selection is made. These "lists" are custom controls, so I could kludge it and put in a "memorized" value that retroactively makes the selection once the control's data source is not null. But that seems like really bad practice. Is there a way to set the sequence of individual control data binding at the form level?
I think your code is getting confused by SelectionChanged events that indicate something got deselected. When you click an unselected item, you are likely to get two events: one indicating nothing is selected (which you may want to ignore, but it needs code to do that), then one indicating the new selection. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
-
I think your code is getting confused by SelectionChanged events that indicate something got deselected. When you click an unselected item, you are likely to get two events: one indicating nothing is selected (which you may want to ignore, but it needs code to do that), then one indicating the new selection. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
That would make sense if these were standard controls. But they are custom controls based on System.Windows.Forms.UserControl -- not inherited from any actual list control like a ListBox. My SelectionChanged() event is a very tightly-coded event that only fires when a value is assigned.
-
That would make sense if these were standard controls. But they are custom controls based on System.Windows.Forms.UserControl -- not inherited from any actual list control like a ListBox. My SelectionChanged() event is a very tightly-coded event that only fires when a value is assigned.
please do not remove a question, it is against the forum guidelines and considered rude. If your problem is solved or no longer relevant to you, leave it as is, but add a marker (such as "solved") to the subject line. If you found the solution yourself, do not hesitate to publish it in the thread, so others can also benefit from it. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
-
please do not remove a question, it is against the forum guidelines and considered rude. If your problem is solved or no longer relevant to you, leave it as is, but add a marker (such as "solved") to the subject line. If you found the solution yourself, do not hesitate to publish it in the thread, so others can also benefit from it. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
I apologize. If it's against forum guidelines, then why is a delete option even available? I removed the question because the more I dug the more confused I got. I decided that I really don't know what the heck is going on and need to do a lot more digging. I thought it would be more courteous to remove the thread altogether than to have people waste their time reading it only to get to the point where I say "never mind, I don't know what I'm talking about".
-
I apologize. If it's against forum guidelines, then why is a delete option even available? I removed the question because the more I dug the more confused I got. I decided that I really don't know what the heck is going on and need to do a lot more digging. I thought it would be more courteous to remove the thread altogether than to have people waste their time reading it only to get to the point where I say "never mind, I don't know what I'm talking about".
well, the remove widget removes a question completely if it has no replies; there is no harm in that. and it replaces the question by "question removed" when there are replies; it really shouldn't be available under those conditions. Removing the head of a thread leaves a sloppy thread; leaving it there may still result in new replies, maybe containing a link to the perfect article dealing with the subject. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
-
well, the remove widget removes a question completely if it has no replies; there is no harm in that. and it replaces the question by "question removed" when there are replies; it really shouldn't be available under those conditions. Removing the head of a thread leaves a sloppy thread; leaving it there may still result in new replies, maybe containing a link to the perfect article dealing with the subject. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).