|
Hi,
I am using Syncfusion in my project and I am showing this ListView:
<SyncfusionListView:SfListView x:Name="ListViewNewItemLocations" SelectionBackgroundColor="Transparent" IsVisible="False" IsScrollBarVisible="false" AutoFitMode="Height" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" ItemAppearing="ListViewNewItemLocations_ItemAppearing" ItemTapped="ListViewNewItemLocations_ItemTapped">
<SyncfusionListView:SfListView.ItemTemplate>
<DataTemplate>
<Frame BorderColor="Black" CornerRadius="25" HasShadow="False">
<StackLayout>
<Label Margin="0,0,0,0" Text="{Binding country_name}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" TextColor="Black" HorizontalTextAlignment="Start" FontSize="15" LineBreakMode="WordWrap" />
<Label Margin="0,0,0,0" Text="{Binding location_address}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" TextColor="Black" HorizontalTextAlignment="Start" FontSize="15" LineBreakMode="WordWrap" />
<Label Margin="0,0,0,0" Text="{Binding telephone}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" TextColor="Black" HorizontalTextAlignment="Start" FontSize="15" LineBreakMode="WordWrap" />
<pre>
<Grid HorizontalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Syncfusionbuttons:SfButton x:Name="ButtonNewItemLocationEdit2" IsVisible="False" BackgroundColor="Brown" Text="Edit" Grid.Column="0" CornerRadius="25" />
<Syncfusionbuttons:SfButton x:Name="ButtonNewItemLocationEdit" Clicked="ButtonNewItemLocationEdit_Clicked_1" ClassId="abcd" BackgroundColor="Brown" Text="Edit" Grid.Column="0" CornerRadius="25" Command="{Binding Path=BindingContext.TapCommand, Source={x:Reference ListViewNewItemLocations}}" CommandParameter="{Binding LocationModel.ItemLocationID}" />
<Syncfusionbuttons:SfButton x:Name="ButtonNewItemLocationDelete" IsVisible="{Binding IsDeleteVisible}" BackgroundColor="Red" Text="Delete" Grid.Column="1" CornerRadius="25" />
</Grid>
</StackLayout>
</Frame>
</DataTemplate>
</SyncfusionListView:SfListView.ItemTemplate>
and I have I have a ViewModel like this:
using System;
using System.Collections.Generic;
using System.Text;
using Syncfusion.ListView.XForms;
using Syncfusion.XForms.PopupLayout;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace Zeera
{
public class ViewModelItemLocation : INotifyPropertyChanged
{
public Command<object> TapCommand { get; set; }
SfPopupLayout popupLayout;
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string name)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(name));
}
public ViewModelItemLocation()
{
TapCommand = new Command<object>(EditButtonTapped);
}
private void EditButtonTapped(object obj)
{
popupLayout = new SfPopupLayout();
popupLayout.PopupView.HeightRequest = 500;
popupLayout.PopupView.WidthRequest = 300;
popupLayout.PopupView.ContentTemplate = new DataTemplate(() =>
{
var mainStack = new StackLayout();
mainStack.BackgroundColor = Color.AliceBlue;
var image = new Image();
image.SetBinding(Image.SourceProperty, new Binding("ContactImage"));
var grid = new Grid();
var NameLabel = new Label()
{
Text = "Customer Name "
};
NameLabel.HorizontalOptions = LayoutOptions.Start;
var label1 = new Entry()
{
};
label1.SetBinding(Entry.TextProperty, new Binding("ContactName"));
label1.HorizontalOptions = LayoutOptions.Start;
var NumberLabel = new Label()
{
Text = "HERE LOCATIO ID"
};
NumberLabel.HorizontalOptions = LayoutOptions.Start;
var label2 = new Entry()
{
};
label2.SetBinding(Entry.TextProperty, new Binding("ContactNumber"));
label2.HorizontalOptions = LayoutOptions.Start;
grid.Children.Add(NameLabel, 0, 0);
grid.Children.Add(label1, 1, 0);
grid.Children.Add(NumberLabel, 0, 1);
grid.Children.Add(label2, 1, 1);
mainStack.Children.Add(image);
mainStack.Children.Add(grid);
return mainStack;
});
popupLayout.PopupView.ShowHeader = false;
popupLayout.PopupView.ShowFooter = false;
popupLayout.HeightRequest = 500;
popupLayout.WidthRequest = 500;
popupLayout.Show();
}
}
}
I have a questions here: How can I pass item_location_id (binded to the SfListView) to the ViewModelItemLocation and then show it in the NumberLabel (created in the ViewModelItemLocation code behind)
Thanks,
Jassim
www.softnames.com
|
|
|
|
|
And you want us to find the relevant field(s) for you?
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hi friends,
I am writing a Unit Test for the method, which has two methods of the same Service are being called, Test method is for the exception case, in one method the Service should return null, it is doing properly, but in the next method it should throw ApplicationException, but it is not throwing, there is no other way to make exception thrown as I need pass the request object and it won't fail there and then calling the Service.
Below is the code for Unit Test, any help would be very very helpful
[TestMethod]
[ExpectedException(typeof(ApplicationException))]
public async Task RegisterOnlineAccountAsync_ExceptionTest()
{
var mockRequest = new OnlineRegistration
{
AccountNumber = "5494526855",
Last4DigitsOfSSN = "4321",
EmailAddress = "abcd@ding.com"
};
var mockPgeAuthResponse = new PgeAuthenticatedUser
{
PersonId = "9013050000",
Email = "abcd@ding.com"
};
PgeAuthenticatedUser mockPgeAuthResponseNull = null;
var mockCCBResponse = new LocatePersonResponse
{
PersonIdList = new List<string> {"9013050000"},
AccountInfoTypes = new List<AccountInfoType>
{
new AccountInfoType
{
AccountNumber = "5494526855",
AccountType = "RES",
MainPersonId = "9013050000"
},
new AccountInfoType
{
AccountNumber = "5494526856",
AccountType = "RES",
MainPersonId = "9013050000"
}
}
};
var mockPaperlessBillResponse = new PaperlessBillResponse
{
EmailAddress = "abcd@ding.com",
IsPaperless = false,
ReceivesCopyOfBill = false
};
var mockPersonDetailResponse = new PersonDetailResponse
{
PersonId = "9013050000",
PersonalIdentifications = new List<PersonalIdentification>
{
new PersonalIdentification
{
Type = "SSN",
Value = "4321"
}
}
};
this._locatePersonContactProxy =
Mock.Of<ILocatePersonContactProxy>(e => e.LocatePersonDetailsAsync(It.IsAny<LocatePersonRequest>()) == Task.FromResult(mockCCBResponse));
this._personDetailsProxy = Mock.Of<IPersonDetailsProxy>(e => e.PersonDetailsGetAsync(It.IsAny<string>()) == Task.FromResult(mockPersonDetailResponse));
this._personManager = Mock.Of<IPersonManager>(e => e.UpdateCcbCssWebUserDetailsAsync(It.IsAny<List<string>>(), It.IsAny<string>()
, It.IsAny<string>(), It.IsAny<string>()) == Task.FromResult(mockPgeAuthResponse));
this._paperlessBillProxy = Mock.Of<IPaperlessBillProxy>(e => e.PaperlessBillingGetAsync(It.IsAny<string>(), It.IsAny<string>()) == Task.FromResult(mockPaperlessBillResponse));
this._paperlessManager = Mock.Of<IPaperlessManager>(e =>
e.PaperlessBillingPreferencesUpdateAsync(It.IsAny<PaperlessBilling>(), It.IsAny<string>(), It.IsAny<string>()) == Task.FromResult(false));
this._customerContactProxy = Mock.Of<ICustomerContactProxy>(e => e.CreateLogAsync(It.IsAny<CustomerContactRequest>()) == Task.FromResult(""));
this._pgeAuthAdminProxy = Mock.Of<IPgeAuthAdminProxy>();
var pgeAuth = new Mock<IPgeAuthAdminProxy>();
pgeAuth.Setup(p => p.GetUserByNameAsync(It.IsAny<string>())).ReturnsAsync(mockPgeAuthResponseNull);
var pgeAuth1 = new Mock<IPgeAuthAdminProxy>();
pgeAuth1.Setup(p => p.CreateUserAccountAsync(It.IsAny<CreateUserAccountRequest>())).Throws(new Exception());
this._pgeMessagingProxy = Mock.Of<IPgeMessagingProxy>(e => e.SendPgeMessageAsync(It.IsAny<PgeMessageRequest>()) == Task.FromResult(false));
this._registrationManager = GetManager();
await this._registrationManager.RegisterOnlineAccountAsync(mockRequest).ConfigureAwait(false);
Assert.ThrowsException<Exception>
(() => new ApplicationException(
$"EmailAddress: ({mockRequest.EmailAddress}) - PersonId: ({mockRequest.PersonId}) - AccountNumber: ({mockRequest.AccountNumber}): Exception caught in AccountManager.Registration.CreateUserOnlineAccountAsync."));
}
The following is the method that needs to be tested:
public async Task<RegisterOnlineAccountResult> RegisterOnlineAccountAsync(OnlineRegistration registration)
{
var registerOnlineAccountResult = new RegisterOnlineAccountResult();
if (registration.PersonId.IsNullOrEmpty())
{
var personDetailsResponse = await this._personDetailsProxy.PersonDetailsGetAsync(registration.PersonId).ConfigureAwait(false);
var cssWebUser = personDetailsResponse?.PersonContactDetails?.FirstOrDefault(pc => pc.ContactType == CSSWebUser);
var xxxAuthenticatedUser = await this._xxxAuthAdminProxy.GetUserByNameAsync(registration.EmailAddress).ConfigureAwait(false);
if (cssWebUser != null)
{
await EnrollUserAsync(response, registration).ConfigureAwait(false);
return new RegisterOnlineAccountResult { OnlineRegistrationAccountResultStatus = OnlineRegistrationAccountResultStatus.Success };
}
if (xxxAuthenticatedUser != null) return new RegisterOnlineAccountResult { OnlineRegistrationAccountResultStatus = OnlineRegistrationAccountResultStatus.WebRegisteredEmailFound };
await EnrollUserAsync(response, registration).ConfigureAwait(false);
registerOnlineAccountResult.OnlineRegistrationAccountResultStatus = OnlineRegistrationAccountResultStatus.Success;
}
else
{
await EnrollStartServiceUser(registration).ConfigureAwait(false);
registerOnlineAccountResult.OnlineRegistrationAccountResultStatus = OnlineRegistrationAccountResultStatus.Success;
}
return registerOnlineAccountResult;
}
private async Task EnrollUserAsync(LocatePersonResponse response, OnlineRegistration onlineRegistration)
{
await CreateUserOnlineAccountAsync(onlineRegistration).ConfigureAwait(false);
}
private async Task<bool> CreateUserOnlineAccountAsync(OnlineRegistration registration)
{
try
{
var request = new CreateUserAccountRequest
{
Description = $"Account created: {DateTime.Now:MM/dd/yyyy}",
AccountType = registration.IsResidential ? nameof(OnlineAccountType.xxxResidentialAcct) : nameof(OnlineAccountType.xxxCommercialAcct),
PersonId = registration.PersonId,
Password = registration.Password,
UserName = registration.EmailAddress,
CcbAccountId = registration.AccountNumber,
BusinessPersonId = !registration.IsResidential ? registration.MainPersonId : null
};
return await this._xxxAuthAdminProxy.CreateUserAccountAsync(request).ConfigureAwait(false);
}
catch (Exception ex)
{
throw new ApplicationException(
$"EmailAddress: ({registration.EmailAddress}) - PersonId: ({registration.PersonId}) - AccountNumber: ({registration.AccountNumber}): Exception caught in AccountManager.Registration.CreateUserOnlineAccountAsync.",
ex);
}
}
If you have seen it here, the _xxxAuthAdminProxy is being called with two different methods 1. GetUserByNameAsync and 2. CreateUserAccountAsync, when condition that needs to happen is GetUserByNameAsync method should return a null where as CreateUserAccountAsync method should throw an exception. any help would be greatly helpful - thanks in advance.
|
|
|
|
|
I think you need to pick an exception that's a little lower in the food chain; you're targetting what would be intended for an app level handler.
Quote: You should derive custom exceptions from the Exception class rather than the ApplicationException class. You should not throw an ApplicationException exception in your code, and you should not catch an ApplicationException exception unless you intend to re-throw the original exception.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I am able to generate mock for one Condition, but not for another condition like, the method GetUserByNameAsync is returning null for the Proxy that I set up as
this._xxxAuthAdminProxy = Mock.Of<IxxxAuthAdminProxy>();
var xxxAuth = new Mock<IxxxAuthAdminProxy>();
xxxAuth.Setup(p => p.GetUserByNameAsync(It.IsAny<string>()))
.ReturnsAsync(mockxxxAuthResponseNull);
xxxAuth.Setup(p => p.CreateUserAccountAsync(It.IsAny<CreateUserAccountRequest>()))
.ThrowsAsync(new Exception());
But CreateUserAccountAsync is not returning exception, any help my friend, anything would be greatly helpful. Thank you.
|
|
|
|
|
I think I told you not to use "ApplicationException" for exceptions "you generate / throw" in you app ... use something else; e.g. throw new Exception("My test blew up as expected");
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
 Where in the Unit Test or in the actual method? From the Actual method I have to use the ApplicationException, even though, I just want to at least throw some Exception from my Unit Test call, but no Exception is being thrown, there is very less help from Online, it seems complicated any help would be very helpful brother rather than giving me high level help.
And I am getting the following error in the Unit Test:
Assert.ThrowsException failed. No exception thrown. Exception exception was expected.
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at CustomerServiceWeb.Library.Test.Registration.RegistrationManagerTest.<RegisterOnlineAccountAsync_ExceptionTest>d__18.MoveNext() in C:\SourceCode\FlexPricing\CustomerServiceWeb.Library.Test\Registration\RegistrationManagerTest.cs:line 692
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Basically Unit test is failing because the Method is not throwing Exception, let it be any Exception, I want to just throw an Exception
I did change it as you said removed the ApplicationException, but still the Unit test is failing:
private async Task<bool> CreateUserOnlineAccountAsync(OnlineRegistration registration)
{
try
{
var request = new CreateUserAccountRequest
{
Description = $"Account created: {DateTime.Now:MM/dd/yyyy}",
AccountType = registration.IsResidential ? nameof(OnlineAccountType.PGEResidentialAcct) : nameof(OnlineAccountType.PGECommercialAcct),
PersonId = registration.PersonId,
Password = registration.Password,
UserName = registration.EmailAddress,
CcbAccountId = registration.AccountNumber,
BusinessPersonId = !registration.IsResidential ? registration.MainPersonId : null
};
return await this._pgeAuthAdminProxy.CreateUserAccountAsync(request).ConfigureAwait(false);
}
catch (Exception ex)
{
throw new Exception("My test blew up as expected");
}
}
modified 22-Apr-19 13:40pm.
|
|
|
|
|
[TestMethod]
[ExpectedException(typeof(ApplicationException))]
public async Task RegisterOnlineAccountAsync_ExceptionTest()
{
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Yes I removed that as well, still not throwing any Exception, any idea my friend?
I did change it to this, still the Exception was not being generated:
[TestMethod]
public async Task RegisterOnlineAccountAsync_ExceptionTest()
Any help would be very very helpful my friend, it seems the problem is in the SetUp itself, I feel so, but I don't know how to generate Exception when the same Proxy was used before for a different method call.
modified 23-Apr-19 17:02pm.
|
|
|
|
|
I have an .NET 4.0 assembly; it is registered in GAC and works as part of a BizTalk “orchestration”.
Sometimes I get the following error - “Collection was modified; enumeration operation might not execute. : System.InvalidOperationException: Collection was modified; enumeration operation might not execute.”. I cannot reproduce it; when I run the same processing of the same data, my assembly does not generate the error in this place.
The error happens when I call ‘.Where(<condition>).ToArray()’ for a datatable object: an object of classd System.Data.TypedTableBase<mydatarowclass>.
Here is the code:
..................
int? setTypeGroupId;
...
return instances.WorkContributors.Where
(
c =>
!c.IsInterestedPartyNoNull()
&& c.InterestedPartyNo == publisherIpNo
&& c.SetTypeNo == 1
&& (c.RecordType == "SPU")
&& c.TypeCode == "E"
&& (!setTypeGroupId.HasValue ||
(setTypeGroupId.HasValue && c.SetTypeGroupID == setTypeGroupId))
)
.ToArray();
..................
The object ‘instances’ is a dataset – my class produced from System.Data.DataSet.
The property ‘instances.WorkContributors’ is a datatable: an object of class System.Data.TypedTableBase<mydatarowclass>.
The class MyDataRowClass is produced from System.Data.DataRow.
The call stack after the error was the following:
Collection was modified; enumeration operation might not execute. : System.InvalidOperationException: Collection was modified; enumeration operation might not execute.
at System.Data.RBTree`1.RBTreeEnumerator.MoveNext()
at System.Linq.Enumerable.<castiterator>d__97`1.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at MyProduct.FileParser.Types.CWR.PWRType.GetPublishers(CWRWorkInstances instances, Nullable`1 setTypeGroupId)
at MyProduct.FileParser.Validation.Concreate.PwrTypeValidation.ValidatePublisherNumber()
at MyProduct.FileParser.Validation.Concreate.PwrTypeValidation.Validate()
at MyProduct.FileParser.Types.CWR.PWRType.StoreRecord(CWRWorkInstances workInstances, CWRWorkParsingContext context)
at MyProduct.FileParser.Groups.CWR.NWRGroup.StoreGroup(Int32 workBatchID, CWRFileCommonData commonData)
at MyProduct.FileParser.CWRParser.ProcessCWRFile(String fileName, Boolean wait, Boolean deleteFile, String sourceFileName)
I cannot understand why the error happens; and why it happens only sometimes and does not happen on the same processed data again.
The error “Collection was modified; enumeration operation might not execute.” Itself is pretty straightforward for me; but I do not see why it happens in that my code. The error is excepted if a code like this:
foreach (DataRow currRow in _someDataTable.Rows)
{
if ()
{
someDataTable.Rows.Remove(currRow);
}
} But my code above just wants to enumerate System.Data.TypedTableBase<mydatarowclass> and convert the result into an array.
Any ideas?
|
|
|
|
|
|
Thank you for the answer, but still not clear:
1. Is this supposed to fix the problem; or to make the problem “stably reproducible”?
2. In any case – what is the root cause of the problem?
|
|
|
|
|
Did you try it? If not why not?
It has to do with "deferred execution". Probably "realizing" while you're "iterating" to an array.
But then again, maybe not. But since you didn't bother to try, we will never know.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
As I recall, a DataTable is not a snapshot, which means that its contents can be changed by another process, such as an insert query. Anything that changes the contents of the list in any way invalidates the snapshot upon which the enumeration depends.
David A. Gray
Delivering Solutions for the Ages, One Problem at a Time
Interpreting the Fundamental Principle of Tabular Reporting
|
|
|
|
|
Tell him. I had no impact. I'll stick with the unmaterialized query result intrusion.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Respected sir,
I've gone through the cryptarithmetic code given in your website. In the description it was given that the starting letter should not be zero(resultantant string one greater than the operand),but in code execution we are getting the initial value as zero. Please explain.
|
|
|
|
|
Sorry but we have no idea what you are referring to. If this is a CodeProject article then please post your question in the form below the article. If it is referring to something else then please provide the link.
|
|
|
|
|
Hi I have a declaration that's as follows, I am looking to initialize this in single statement rather than initializing individually
private IList<MockData<OnlineRegistration, OnlineRegistration, OnlineRegistration>> _registerMocks;
What I want is obj1, obj2, obj3 of the OnlineRegistration Objects to be initialized within one single statement, it can have multiple lines, don't confuse but values of the these objects all should be set within one statement.
Like:
var obj1 = new OnlineRegistration {Id=1, Name="xyz"}
var obj2 = new OnlineRegistration {Id=2, Name="abc"}
var obj3 = new OnlineRegistration {Id=2, Name=".Net Fun"}
these objects should go into one single initialization of the above statement, any ways? please
|
|
|
|
|
simpledeveloper wrote: of the these objects all should be set within one statement. You are wasting time and effort to get them on a single line, while it has no benefit to do so.
Even more, if you make it into a single statement, it will execute and fail as one. If you use multiple statements, you can use breakpoints on each statement, and have them evaluate individually, which makes finding errors a bit simpeler.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hello Developers, I am new to ASP.Net core 2.0.1, i studied the architecture of Authentication and identification in core framework,i facing some problems during migration, please help. In the Startup.cs file, I am using this piecce of code in ConfigureServices method
app.use(async (context, next) =>
{
await context.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
await context.Authentication.ChallengeAsync(CookieAuthenticationDefaults.AuthenticationScheme);
await next.Invoke();
}
Now in core, i dont know how to handle these 2 functions for logout
I get NULLREFERENCE Exception
var projectId = context?.Session?.GetInt("Project_Id"); when page is refershed after a while.
Please help me to resolve these issue.
Geetha
modified 25-Mar-19 4:36am.
|
|
|
|
|
Message Closed
modified 9-Mar-19 4:10am.
|
|
|
|
|
Just use MS Power BI for the desktop and be done with it.
Power BI Desktop | Microsoft Power BI
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
|
I sort of got that from his last line. Just wanted to irritate him by stealing his soapbox.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I am building an application in WPF for the first time. The application is intended to track employees who are hired by the company, track the hire type (e.g…assignment category…full time, part time, seasonal, intern). In addition, it will track which department to which an employee is assigned during their tenure with the company. Some employees are exposed to several different departments while employed in order to more fully round out their training or due to work loads.
The backend for this application is built in SQL Server and contains three tables. They are company employees, company departments, and assignment categories. Each obviously has its own primary key.
I have created a datagrid that, via Linq to SQL Classes, displays data from the company employees table. Each of the columns in the datagrid is a DataGridTextColumn except for one which is a DataGridComboBoxColumn. The DataGridTextColumn’s work fine. However, I cannot seem to get the binding correct. The column appears in the datagrid and is a working combobox. The issue is that I cannot find how to populate the combox with values from which the end user will select. This combobox will allow the end user to choose which under which assignment category an employee has been hired.
As an end result, this application will be used by the company owner to keep track of the number of employees that he has on hand and show who will be leaving each month due to being a seasonal worker or an intern.
Below is the code behind and the xaml. Please note that I have spent several days now researching this topic and cannot find anything that I can make work. I am confident that this is because I am just learning xaml and c#.
Can someone help me understand what I am doing wrong, please?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace staff_scheduling_tool.views
{
public partial class employees_new_employee : UserControl
{
assignment_typeDataContext dc = new assignment_typeDataContext(Properties.Settings.Default.db_employee_scheduling_applicationConnectionString);
public employees_new_employee()
{
InitializeComponent();
if (dc.DatabaseExists()) datagrid_search_results.ItemsSource = dc.companyemployees;
}
private void Save_changes_Click(object sender, RoutedEventArgs e)
{
dc.SubmitChanges();
}
}
}
<DataGrid Name="datagrid_search_results" Margin="10,25" Width="1400" Height="350" AlternatingRowBackground="LightGreen" GridLinesVisibility="None" SelectionUnit="Cell" BorderBrush="Transparent" BorderThickness="0" Background="Transparent" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding employee_id}" Width="Auto" Header=" Employee ID" />
<DataGridTextColumn Binding="{Binding last_name}" Width="Auto" Header=" Last Name" SortDirection="Ascending" />
<DataGridTextColumn Binding="{Binding first_name}" Width="Auto" Header=" First Name"/>
<DataGridTextColumn Binding="{Binding middle_name}" Width="Auto" Header=" Middle Name"/>
<DataGridTextColumn Binding="{Binding company_email}" Width="Auto" Header=" Company Email"/>
<DataGridComboBoxColumn Width="Auto" Header="Assignment Category" />
<DataGridTextColumn Binding="{Binding department_assignment_begin_date, StringFormat=d}" Width="Auto" Header=" Begin Date"/>
<DataGridTextColumn Binding="{Binding department_assignment_end_date, StringFormat=d}" Width="Auto" Header=" End Date"/>
</DataGrid.Columns>
</DataGrid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="45"/>
</Grid.RowDefinitions>
<Button Name="save_changes" Content="Save Updates" Click="Save_changes_Click" Grid.Row="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Width="250" FontFamily="Sitka Banner" FontSize="24" FontStyle="Italic" FontWeight="ExtraBold"/>
</Grid>
modified 28-Feb-19 17:42pm.
|
|
|
|
|