Combobox in WPF unable to add hardcode values with database values
XAML Code:
<ComboBox x:Name="CbLinge" HorizontalAlignment="right" Margin="0,150,0,0" VerticalAlignment="Top" Width="300" Height="25" RenderTransformOrigin="1.018,0.565 "
ItemsSource="{Binding GetLinge}"
DisplayMemberPath="Linge"
SelectedValuePath="Linge"
SelectedValue="{Binding FinishedManual.Ligne}"/>
C# Code:
public void _fillLinge()
{
List<FinishedManualPrintingLinge> linge = _finishedProductService.GetFinishedManualLinge().ToList();
foreach (var item in linge)
{
GetLinge.Add(item);
}
}
By This piece of code,I'm able to get the values from database and able to display in Dropdown.
Problem:
The dropdown list for "Ligne" is linked to data available in order table. But if any order for the line, then it is not visible in drop-down "Ligne". So, it should be hardcoded/ populated by (1,4,6,7,8,9,10).
Now, I am not sure how to display the hardcode values if order : x is selected.
c# wpf
add a comment |
XAML Code:
<ComboBox x:Name="CbLinge" HorizontalAlignment="right" Margin="0,150,0,0" VerticalAlignment="Top" Width="300" Height="25" RenderTransformOrigin="1.018,0.565 "
ItemsSource="{Binding GetLinge}"
DisplayMemberPath="Linge"
SelectedValuePath="Linge"
SelectedValue="{Binding FinishedManual.Ligne}"/>
C# Code:
public void _fillLinge()
{
List<FinishedManualPrintingLinge> linge = _finishedProductService.GetFinishedManualLinge().ToList();
foreach (var item in linge)
{
GetLinge.Add(item);
}
}
By This piece of code,I'm able to get the values from database and able to display in Dropdown.
Problem:
The dropdown list for "Ligne" is linked to data available in order table. But if any order for the line, then it is not visible in drop-down "Ligne". So, it should be hardcoded/ populated by (1,4,6,7,8,9,10).
Now, I am not sure how to display the hardcode values if order : x is selected.
c# wpf
What do you mean by But if any order for the line, then it is not visible in drop-down "Ligne".?
– Alain Elemia
Nov 22 '18 at 5:10
try to filter as this one stackoverflow.com/a/16938351/713789
– Anirudha Gupta
Nov 22 '18 at 5:11
@Alain: example we have 1 more drop-down above which is displaying orders. Now if user select the order which doesn't have and existing value of linge. So in that case my drop- down will show (1,4,6,7,8,9,10) values.
– Naman
Nov 22 '18 at 6:53
So you want to have aFallBack
value for your collectionBinding
. It is easy enough, also you clicked on combobox and rotated it a bit, you don't needSelectedValuePath
when you useSelectedValue
.
– XAMlMAX
Nov 22 '18 at 8:34
Have you had any luck with this?
– XAMlMAX
Nov 26 '18 at 10:17
add a comment |
XAML Code:
<ComboBox x:Name="CbLinge" HorizontalAlignment="right" Margin="0,150,0,0" VerticalAlignment="Top" Width="300" Height="25" RenderTransformOrigin="1.018,0.565 "
ItemsSource="{Binding GetLinge}"
DisplayMemberPath="Linge"
SelectedValuePath="Linge"
SelectedValue="{Binding FinishedManual.Ligne}"/>
C# Code:
public void _fillLinge()
{
List<FinishedManualPrintingLinge> linge = _finishedProductService.GetFinishedManualLinge().ToList();
foreach (var item in linge)
{
GetLinge.Add(item);
}
}
By This piece of code,I'm able to get the values from database and able to display in Dropdown.
Problem:
The dropdown list for "Ligne" is linked to data available in order table. But if any order for the line, then it is not visible in drop-down "Ligne". So, it should be hardcoded/ populated by (1,4,6,7,8,9,10).
Now, I am not sure how to display the hardcode values if order : x is selected.
c# wpf
XAML Code:
<ComboBox x:Name="CbLinge" HorizontalAlignment="right" Margin="0,150,0,0" VerticalAlignment="Top" Width="300" Height="25" RenderTransformOrigin="1.018,0.565 "
ItemsSource="{Binding GetLinge}"
DisplayMemberPath="Linge"
SelectedValuePath="Linge"
SelectedValue="{Binding FinishedManual.Ligne}"/>
C# Code:
public void _fillLinge()
{
List<FinishedManualPrintingLinge> linge = _finishedProductService.GetFinishedManualLinge().ToList();
foreach (var item in linge)
{
GetLinge.Add(item);
}
}
By This piece of code,I'm able to get the values from database and able to display in Dropdown.
Problem:
The dropdown list for "Ligne" is linked to data available in order table. But if any order for the line, then it is not visible in drop-down "Ligne". So, it should be hardcoded/ populated by (1,4,6,7,8,9,10).
Now, I am not sure how to display the hardcode values if order : x is selected.
c# wpf
c# wpf
asked Nov 22 '18 at 5:01
NamanNaman
67
67
What do you mean by But if any order for the line, then it is not visible in drop-down "Ligne".?
– Alain Elemia
Nov 22 '18 at 5:10
try to filter as this one stackoverflow.com/a/16938351/713789
– Anirudha Gupta
Nov 22 '18 at 5:11
@Alain: example we have 1 more drop-down above which is displaying orders. Now if user select the order which doesn't have and existing value of linge. So in that case my drop- down will show (1,4,6,7,8,9,10) values.
– Naman
Nov 22 '18 at 6:53
So you want to have aFallBack
value for your collectionBinding
. It is easy enough, also you clicked on combobox and rotated it a bit, you don't needSelectedValuePath
when you useSelectedValue
.
– XAMlMAX
Nov 22 '18 at 8:34
Have you had any luck with this?
– XAMlMAX
Nov 26 '18 at 10:17
add a comment |
What do you mean by But if any order for the line, then it is not visible in drop-down "Ligne".?
– Alain Elemia
Nov 22 '18 at 5:10
try to filter as this one stackoverflow.com/a/16938351/713789
– Anirudha Gupta
Nov 22 '18 at 5:11
@Alain: example we have 1 more drop-down above which is displaying orders. Now if user select the order which doesn't have and existing value of linge. So in that case my drop- down will show (1,4,6,7,8,9,10) values.
– Naman
Nov 22 '18 at 6:53
So you want to have aFallBack
value for your collectionBinding
. It is easy enough, also you clicked on combobox and rotated it a bit, you don't needSelectedValuePath
when you useSelectedValue
.
– XAMlMAX
Nov 22 '18 at 8:34
Have you had any luck with this?
– XAMlMAX
Nov 26 '18 at 10:17
What do you mean by But if any order for the line, then it is not visible in drop-down "Ligne".?
– Alain Elemia
Nov 22 '18 at 5:10
What do you mean by But if any order for the line, then it is not visible in drop-down "Ligne".?
– Alain Elemia
Nov 22 '18 at 5:10
try to filter as this one stackoverflow.com/a/16938351/713789
– Anirudha Gupta
Nov 22 '18 at 5:11
try to filter as this one stackoverflow.com/a/16938351/713789
– Anirudha Gupta
Nov 22 '18 at 5:11
@Alain: example we have 1 more drop-down above which is displaying orders. Now if user select the order which doesn't have and existing value of linge. So in that case my drop- down will show (1,4,6,7,8,9,10) values.
– Naman
Nov 22 '18 at 6:53
@Alain: example we have 1 more drop-down above which is displaying orders. Now if user select the order which doesn't have and existing value of linge. So in that case my drop- down will show (1,4,6,7,8,9,10) values.
– Naman
Nov 22 '18 at 6:53
So you want to have a
FallBack
value for your collection Binding
. It is easy enough, also you clicked on combobox and rotated it a bit, you don't need SelectedValuePath
when you use SelectedValue
.– XAMlMAX
Nov 22 '18 at 8:34
So you want to have a
FallBack
value for your collection Binding
. It is easy enough, also you clicked on combobox and rotated it a bit, you don't need SelectedValuePath
when you use SelectedValue
.– XAMlMAX
Nov 22 '18 at 8:34
Have you had any luck with this?
– XAMlMAX
Nov 26 '18 at 10:17
Have you had any luck with this?
– XAMlMAX
Nov 26 '18 at 10:17
add a comment |
1 Answer
1
active
oldest
votes
OPTION 1
Display a hardcoded set of values:
Here is how I have done it:
<ComboBox ItemsSource="{Binding GetLinge, TargetNullValue='123456789', FallbackValue='123456789'}"/>
In your case you would use the TargetNullValue
to populate the values. The 10
might be a bit tricky as the string is IEnumerable
so it will pick single characters from the array. But I think this will push you in the right direction.
OPTION 2
Another option is to modify your public void _fillLinge()
method and let it return default values if there aren't any found.
OPTION 3
Another Option would be to use a converter which would then supply the default items instead of modifying the public void _fillLinge()
method.
The choice is yours.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424170%2fcombobox-in-wpf-unable-to-add-hardcode-values-with-database-values%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
OPTION 1
Display a hardcoded set of values:
Here is how I have done it:
<ComboBox ItemsSource="{Binding GetLinge, TargetNullValue='123456789', FallbackValue='123456789'}"/>
In your case you would use the TargetNullValue
to populate the values. The 10
might be a bit tricky as the string is IEnumerable
so it will pick single characters from the array. But I think this will push you in the right direction.
OPTION 2
Another option is to modify your public void _fillLinge()
method and let it return default values if there aren't any found.
OPTION 3
Another Option would be to use a converter which would then supply the default items instead of modifying the public void _fillLinge()
method.
The choice is yours.
add a comment |
OPTION 1
Display a hardcoded set of values:
Here is how I have done it:
<ComboBox ItemsSource="{Binding GetLinge, TargetNullValue='123456789', FallbackValue='123456789'}"/>
In your case you would use the TargetNullValue
to populate the values. The 10
might be a bit tricky as the string is IEnumerable
so it will pick single characters from the array. But I think this will push you in the right direction.
OPTION 2
Another option is to modify your public void _fillLinge()
method and let it return default values if there aren't any found.
OPTION 3
Another Option would be to use a converter which would then supply the default items instead of modifying the public void _fillLinge()
method.
The choice is yours.
add a comment |
OPTION 1
Display a hardcoded set of values:
Here is how I have done it:
<ComboBox ItemsSource="{Binding GetLinge, TargetNullValue='123456789', FallbackValue='123456789'}"/>
In your case you would use the TargetNullValue
to populate the values. The 10
might be a bit tricky as the string is IEnumerable
so it will pick single characters from the array. But I think this will push you in the right direction.
OPTION 2
Another option is to modify your public void _fillLinge()
method and let it return default values if there aren't any found.
OPTION 3
Another Option would be to use a converter which would then supply the default items instead of modifying the public void _fillLinge()
method.
The choice is yours.
OPTION 1
Display a hardcoded set of values:
Here is how I have done it:
<ComboBox ItemsSource="{Binding GetLinge, TargetNullValue='123456789', FallbackValue='123456789'}"/>
In your case you would use the TargetNullValue
to populate the values. The 10
might be a bit tricky as the string is IEnumerable
so it will pick single characters from the array. But I think this will push you in the right direction.
OPTION 2
Another option is to modify your public void _fillLinge()
method and let it return default values if there aren't any found.
OPTION 3
Another Option would be to use a converter which would then supply the default items instead of modifying the public void _fillLinge()
method.
The choice is yours.
edited Nov 22 '18 at 9:21
answered Nov 22 '18 at 8:45
XAMlMAXXAMlMAX
1,8731920
1,8731920
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424170%2fcombobox-in-wpf-unable-to-add-hardcode-values-with-database-values%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What do you mean by But if any order for the line, then it is not visible in drop-down "Ligne".?
– Alain Elemia
Nov 22 '18 at 5:10
try to filter as this one stackoverflow.com/a/16938351/713789
– Anirudha Gupta
Nov 22 '18 at 5:11
@Alain: example we have 1 more drop-down above which is displaying orders. Now if user select the order which doesn't have and existing value of linge. So in that case my drop- down will show (1,4,6,7,8,9,10) values.
– Naman
Nov 22 '18 at 6:53
So you want to have a
FallBack
value for your collectionBinding
. It is easy enough, also you clicked on combobox and rotated it a bit, you don't needSelectedValuePath
when you useSelectedValue
.– XAMlMAX
Nov 22 '18 at 8:34
Have you had any luck with this?
– XAMlMAX
Nov 26 '18 at 10:17