Posts

Donate

How To Upload And Publish Visual Studio 2012 Project To GitHub

Image
Hello, In this tutorial, I will demonstrate on how to upload and publish a Visual Studio 2012 project to GitHub. Steps 1 and 2 are needed because editions of Visual Studio (2013 and 2015) has built-in extension for Git. So to start with, perform the detailed steps below. 1. Close all instance of Visual Studio. Download and Install Visual Studio 2012 Update 4 (Latest Update) 2. Download and Install Visual Studio Tools for Git. (Search in marketplace.visualstudio.com) 3. Create a sample Repository. (Uncheck Initialize this repository with a README) 4. Copy the url generated by the repository with .git extension. This will be used when you publish the project. 5. Open Sample project to be committed. Right click on the solution and choose Git instead of Team Foundation Version Control. 6. Open Team Explorer via View Menu (View-> Team Explorer). 7. Click Home (Home icon) and then choose Changes. This will open up the project in which you can select files to be Included o...

Github Repository (DotNetGenetics)

Hi! Today, I just created a repository account in GitHub .NET Genetics . I'll be adding some snippets and projects posted in this blog or in the .NET Community VBForums. Cheers! :-)

AllowUsersToAddRows In DataGridView Not Working If DataSource is List<T>

Greetings! Going back to a previous project of mine, I found out that some DataGridView control's DataSource where set using List<T> and as a result, prevented the users to add new data to the DataGridView. private void List() { List<Item> list = new List<Item>(); for ( int i = 0; i < 100; i++) { list.Add( new Item() { ID = i, Name = String.Format( "{0}:{1}" , "Test" , i.ToString()) }); } DataGridView1.DataSource = list; } The common solution is to use DataTable as the DataSource but if we want to use a List type object, we could use BindingList<T> or BindingSource. Both of these have AllowNew property which indicates that you can add items to the list using the AddNew() method. It is stated in DataGridView.AllowUsersToAddRows that " If the DataGridView is bound to data, the user is allowed to add rows if both this property and the data source's IBindingList.AllowNew property are set to true. ".Well, Lis...

Unexpected character encountered while parsing value: C. Path '', line 0, position 0. (Deserialize JSON String Error In C#)

Hi, A common issue when deserializing a JSON object in C# is to pass the filepath of the JSON file to the Deserialize() method instead of the string content of that file such as the code below. var obj = JsonConvert.DeserializeObject<Employee>( @"D:\Data\Employee.json" ) When calling the Deserialize() method, you need to make sure that the parameter passed is a JSON string value instead of the file path. Use StreamReader class or File.ReadAllText() to get the content of the JSON file. using (StreamReader reader = new StreamReader( @"D:\Data\Employee.json" )) { string json = reader.ReadToEnd(); var obj = JsonConvert.DeserializeObject<Employee>(json); }

Exclude Property Mapping In Entity Framework Code First Approach

Hi all, Given a database table such as User with fields Id, UserName and Password that will be mapped to a class using Entity Framework called User with an additional field of ConfirmPassword. public class User { public int Id { get ; set ; } public string UserName { get ; set ; } public string Password { get ; set ; } public string ConfirmPassword { get ; set ; } } I would like to exclude the ConfirmPassword field from being mapped to the User table. So, after doing some searching, the solution is to decorate the property with [NotMapped] attribute and make sure to reference the DataAnnotations namespace ( System.ComponentModel.DataAnnotations.Schema ). using System.ComponentModel.DataAnnotations.Schema; public class User : IEntity { public int Id { get ; set ; } public string UserName { get ; set ; } public string Password { get ; set ; } [NotMapped] public string ConfirmPassword { get ; set ; } }

Update DataTable Values Using LINQ In C# And VB.NET

Image
Hello, Here's how to update DataTable value(s) using Method or Query syntax in LINQ. C# Code private void Form1_Load( object sender, EventArgs e) { DataTable dt = new DataTable( "tblEntTable" ); dt.Columns.Add( "ID" , typeof ( string )); dt.Columns.Add( "Amount" , typeof ( decimal )); dt.Rows.Add( new object [] { "1" , 100.51}); dt.Rows.Add( new object [] { "2" , 200.52}); dt.Rows.Add( new object [] { "3" , 500.24}); dt.Rows.Add( new object [] { "4" , 400.31}); dt.Rows.Add( new object [] { "5" , 600.88}); dt.Rows.Add( new object [] { "6" , 700.11}); //QuerySyntax(dt); MethodSyntax(dt); } private void QuerySyntax(DataTable dt) { var result = from row in dt.AsEnumerable() select new { ID = row.Field< string >( "ID" ), Amount = 900.23 }; DataGridView1.DataSource = result.ToList(); } private void MethodSyntax(DataTa...

String was not recognized as a valid DateTime (Assign date value with dd-MM-yyyy format to DateTimePicker control)

Good day! A question was raised on how to assign a date value with format dd-MM-yyyy (05-11-2016) to a DateTimePicker control Text property. Using Convert.ToDateTime() to assign the given value will cause an exception String was not recognized as a valid DateTime . So, a workaround for this is to parse the date value using DateTime.ParseExact() as presented below. The default format of the DateTimePicker control is long. var dateObj = DateTime.ParseExact( "05-11-2016" , "dd-MM-yyyy" , CultureInfo.InvariantCulture); DateAttendancePicker.Text = dateObj.ToString(); Make sure that the second parameter of the function is the correct format of the input value.

DataGridView ComboBox Cascade In Windows Forms

Image
Good day to all! Here's an example of how to perform a combobox lookup or cascade using two DataGridViewComboBoxColumns inside a DataGridView control Combo Lookup in DGV . The solution presented is in VB.NET, so I decided to create a C# equivalent for this. In form load event, populate two DataTables for Roles and Employees. Each employee is assigned to a specific role. private void Form1_Load( object sender, EventArgs e) { DataGridView1.Rows.Add(); dtRole.Columns.Add( "RoleID" ); dtRole.Columns.Add( "RoleName" ); dtRole.Rows.Add(1, "Admin" ); dtRole.Rows.Add(2, "Instructor" ); dtRole.Rows.Add(3, "Utility" ); dtEmployee.Columns.Add( "RoleID" ); dtEmployee.Columns.Add( "EmployeeID" ); dtEmployee.Columns.Add( "EmployeeName" ); dtEmployee.Rows.Add(1, 1, "Sam" ); dtEmployee.Rows.Add(1, 2, "Nicole" ); dtEmployee.Rows.Add(2, 3, "Donald" ); dtEmployee.Rows.Add(...

DataGridViewComboBoxColumn Show Dropdown In Single Click Instead Of Double Click

Hi, When adding DataGridViewComboBoxColumn control to a DataGridView control, the dropdown shows when you double click instead of single click. The common fix to this is to set the EditMode property to EditOnEnter . Given that you don't want to alter the default settings of the DataGrid control and you want to handle it through code,I found the solution in this website DATAGRIDVIEWCOMBOBOXCOLUMN REQUIRES MULTIPLE CLICKS TO SELECT AN ITEM from a comment made by a developer. However, there's a slight issue in the code provided since a column index returned might have a -1 index and this will cause an Unhandled Exception . The revision made is to add a condition that will check if the ColumnIndex of the DataGridView cell is greater than or equal to 0. private void DataGridView1_CellClick( object sender, DataGridViewCellEventArgs e) { DataGridView grid = (DataGridView)sender; if (e.ColumnIndex >= 0) { if (grid.Columns[e.ColumnIndex].Name == "Role" || grid....

Login To Facebook Account Using C#, Webbrowser And LINQ

Hi, Here's how to login to your facebook account using Webbrowser control and LINQ in Windows Forms. The input elements are checked through their attributes like "email" for email fields, "password" for password fields and "submit" for submission control. These codes are inside the DocumentCompleted event. C# code WebBrowser1.Document.GetElementsByTagName( "input" ).Cast<HtmlElement>().FirstOrDefault(t => t.GetAttribute( "type" ) == "email" ).SetAttribute( "value" , "your email address" ); WebBrowser1.Document.GetElementsByTagName( "input" ).Cast<HtmlElement>().FirstOrDefault(t => t.GetAttribute( "type" ) == "password" ).SetAttribute( "value" , "your user name" ); WebBrowser1.Document.GetElementsByTagName( "input" ).Cast<HtmlElement>().FirstOrDefault(t => t.GetAttribute( "type" ) == "submit" ).I...

Donate