Posts

Donate

Get Microsoft Excel Cell Value Using C# And Office.Interop.Excel

Hello, In this article, I'll show you two options to get the cell value of excel using C#. Given that you are using VSTO and have referenced the assembly Microsoft.Office.Interop.Excel. 1 2 3 var cellValue = ( string )(xlWorkSheet.Cells[3, 6] as Excel.Range).Value2; //or this var cellValue = xlWorkSheet.get_Range( "F3" , Type.Missing).Value2; Note: xlWorkSheet is an Excel Worksheet object.

How To Implement IEnumerable<T> Interface In C# And VB.NET

Image
Hello, According to MSDN, IEnumerable<T> Interface exposes the enumerator, which supports a simple iteration over a collection of a specified type. Collections such as List<T> implements this interface. For this demo, I created a simple class that implements IEnumerable<string>. You can use concrete types instead of string or ordinary data types. Presented are two classes in different languages (C# and VB.NET) that implements the interface. Notice that in VB.NET, the yield functionality is applied in an Iterator function. C#.NET 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 namespace IEnumerableExample { class Program { static void Main( string [] args) { MessagingApp myObject = new MessagingApp(); foreach ( string item in myObject) { Console.WriteLine(item); } Console.

How To Wrap Text In A DataGridViewColumn

Image
Given that you have data such as comments/notes/description/address that would comprise at least hundreds of characters and you want to show them on the DataGridView control, you will notice that the text is concatenated and replaced with ellipses. In order to achieve wrapping of text in a DataGridView cell, I achieved it using these steps. 1. Change the WrapMode value to True of a DataGridViewTextBoxColumn's DefaultCellStyle. 2. In my DataBindingComplete event of the DataGridView, set the AutoSizeRowsMode of the DataGridView to AllCells. C# Code private void dgvFormat_DataBindingComplete( object sender, DataGridViewBindingCompleteEventArgs e) { dgvFormat.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; } That's it.. :-)

Return Top Three Largest Values In A VB.NET Array Using LINQ

Sample snippet on getting the three largest values in an array using LINQ. VB.NET 1 2 3 4 5 6 7 8 9 10 11 12 13 Dim rand As New Random() Dim numbers As New List( Of Int32) For index = 1 To 20 Step 1 ' add a list item which is a number from 1 through 100 numbers.Add(rand.Next(1, 100)) Next Dim topThreeLargest = numbers.OrderByDescending(Function(t) t).Take(3) Console.WriteLine( "Top three largest elements in the array: " ) For Each item As String In topThreeLargest Console.WriteLine(item) Next

Set Url Parameter Of $.getJSON() Method Using @Url.Action() In ASP.NET MVC

Here's how you set the first parameter of $.getJSON() which is url using @Url.Action() where GetProductDetails is the action name and Product is the controller name. Make sure to surround it with single quotes. Javascript Code: 1 2 3 4 5 function GetProductData(event) { $.getJSON( '@Url.Action("GetProductDetails","Product")' , function (prod) { alert(prod); }); }

Append QueryString To PostBackUrl Attribute In ASP.NET Web Forms LinkButton Control Inside GridView Control

There was a question raised in the forum on how to append query string to a PostbackUrl attribute in an ASP.NET LinkButton inside the template field of a GridView control. To answer that, one possible solution is to set the PostBackUrl with String.Format() method where you can include the desired query string of that url. 1 2 3 4 <asp:LinkButton ID= "lnkProductPage" runat= "server" PostBackUrl= '<%# String.Format("ProductPage.aspx?Id={0}", Eval("ID"))%>' CausesValidation= "false" Text= '<%# Eval("ID")%>' > </asp:LinkButton>

VBForums CodeBank Entries

ASP.NET/ASP.NET MVC Using Bootstrap Typeahead.js Plugin in an ASP.NET MVC Project Using AJAX Control Toolkit AutoCompleteExtender in ASP.NET 4.5 ASP.NET MVC ListBoxFor() with optgroup Tag support ASP.NET FormView CRUD (Create, Update, Delete) with EF Using jqGrid with ASP.NET MVC 5 Visual Basic.NET ASP.NET MVC 5 Form Validation using jQuery and Bootstrap w/o Model Alphabetical Paging in ASP.NET MVC Bootstrap Modal Dialog in ASP.NET 4.5 ASP.NET GridView CRUD with Bootstrap (VB.NET) ASP.NET MVC TextBox Helper Watermark Databinding ASP.NET GridView with jQuery Read-only column on GridView Row Editing Change GridView SortLink Color in ASP.NET 4.0 Change ASP.NET Label control value using continuous mouse down click C#.NET

ASP.NET FormView CRUD With Entity Framework (VB.NET)

Image
The VB.NET version of this post ASP.NET FormView CRUD with Entity Framework is provided in the ASP.NET Codebank section of VBForums ASP.NET FormView CRUD (Create, Update, Delete) with Entity Framework . Screenshots

ASP.NET FormView CRUD With Entity Framework

Image
Most of the examples on FormView Web Server control use DataSource wizard controls such as SqlDatasource or ObjectDataSource when assigning value to the FormView's DataSource property. However, using those controls have drawbacks such as maintainability. I also found samples out there using ADO.NET. Enough with the chit-chat and let's proceed with coding. I'll post the create table statement, code behind and the aspx markup. SQL Code: USE [Books] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[BookDetails]( [BookSerialNo] [int] IDENTITY (1,1) NOT NULL , [BookISBN] [ nchar ](15) NULL , [BookTitle] [varchar](120) NULL , [BookAuthor] [varchar](60) NULL , [BookPublisher] [varchar](50) NULL , [BookCategory] [varchar](20) NULL , PRIMARY KEY CLUSTERED ( [BookSerialNo] ASC ) WITH (PAD_INDEX = OFF , STATISTICS_NORECOMPUTE = OFF , IGNORE_DUP_KEY = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_

DataKey Value Is Null In ItemDeleting Event Of ASP.NET Web Forms FormView Control

Image
Hello, Normally, you can access the DataKey object value of a FormView control to it's wired events. Since I'm using Entity Framework as Datasource of a FormView control instead of DataSource control wizards, the DataKey object value of the FormView control returns null instead of an ID in the ItemDeleting event of that object. After putting several breakpoints to it's events, I came up with a fix that is to query the DB again and then bind it's result to the DataSource property of the FormView Control. That is call BindFormView() method when CommandName is equal to "Delete" in the ItemCommand event of the control. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 protected void FormViewBookDetails_ItemCommand( object sender, FormViewCommandEventArgs e) { if (e.CommandName == "Cancel" ) { FormViewBookDetails.ChangeMode(FormViewMode.ReadOnly); } else if (e.CommandName == "Edi

Donate