Posts

Donate

Regular Expression In html List Tag Not Working In Multiline String In C#

I have this string: < li class="MsoNormal" style="color:white;mso-themecolor:background1; mso-margin-top-alt:mso-list:l1 level1 lfo1;tab-stops:list 36.0pt"> and the regex has a lazy quantifier to replace the string above to < li>. Using a simple regex pattern, it won't change the string above to ordinary < li>. The solution would be to add a regex to replace new line characters. Since the string has newline characters. Regex.Replace(source, @"\n" , string .Empty, RegexOptions.IgnoreCase);

How To Set Background Color Of Excel Cell Using C#

Image
Good evening! Here's how to set MS Excel cell or cells background color using C# Excel.Range class in two different solutions. chartRange = sheet.Cells[ 1 , i + 1 ]; chartRange.Interior.Color = Color.LightBlue; or using get_Range() function and ColorTranslator.ToOle() to set the background color. Excel.Range chartRange; chartRange = xlWorkSheet.get_Range( "b1" , "b3" ); chartRange.Interior.Color = ColorTranslator.ToOle(Color.Red); Where chartRange is a RangeObject.

Clear Checkboxes Inside GroupBox Not Working In C# Windows Forms

In a project that i am working with, I have 18 checkboxes. Normally the code below should clear all 18 checkboxes in the groupbox. private void ClearChecklist(GroupBox control) { foreach (Control checklist in control.Controls) { if (checklist is CheckBox) { ((CheckBox)checklist).Checked = false ; } } } However only 14 checkboxes are deselected. So I modified the code to this: private void ClearChecklist(GroupBox control) { if (visited_recursion &lt;= 1) { foreach (Control checklist in control.Controls) { if (checklist is CheckBox) { ((CheckBox)checklist).Checked = false ; } } visited_recursion++; ClearChecklist(grpActiveSiteCategories); } } I applied a recursion only once to prevent infinite loop/exception.

Method's type signature is not Interop compatible. [Copying DataGridValues to excel cell object]]

I have this original snippet which copies datagridview values into the microsoft excel sheet: for ( int i = 0; i < dataGridViewObjects[gcount].Columns.Count; i++) { sheet.Cells[1, i + 1] = dataGridViewObjects[gcount].Columns[i].Name; for ( int row = 0; row < dataGridViewObjects[gcount].Rows.Count; row++) { for ( int column = 0; column < dataGridViewObjects[gcount].Columns.Count; column++) { sheet.Cells[row + 2, column + 1] =dataGridViewObjects[gcount].Rows[row].Cells[column].Value; } } } The code above throws an exception of method type signature is not interop compatible. I was debugging and checking MSDN classes on Workbook. When I debugged at adding cell values, i did catch the exception. The solution is simple. Just add ToString() after the value, since value is of type object. sheet.Cells[row + 2, column + 1] = dataGridViewObjects[gcount].Rows[row].Cells[column].Value.ToString();

MySQL Subquery Result As Aliased Table Name

Here's a query that has a subquery in which the result is aliased as inner table and then the outer query compares the result from the subquery against the field in the outer query. SELECT id,w_id, start , f_count, count_percent FROM tblLogs, ( select max (id) as max_id from tblLogs where w_id = 92 and categ = 'bike' and date( start ) = '2012-01-24' ) as inner_table WHERE DATE( start ) = '2012-01-24' AND w_id =92 AND categ = 'bike' and err = 'none' and remark = '' and inner_table.max_id = tblLogs.id;

Equi-Join In MySQL Example

Here's an example of equi join select distinct site_scripts._id, crw_site.site, crw_subcategory.subcategory from site_scripts, crw_site , crw_subcategory where site_scripts.subcategory_id = 8 and crw_site._id = site_scripts._id and crw_subcategory.subcategory_id = site_scripts.subcategory_id and crw_scripts.country_id = 1 and crw_site._active = 1 order by crw_site.site; Note: The concept can be used as an alternate to inner join...

How To Sort Dictionary<TKey,TValue> Object By Value Or By Key Using LINQ In C#

Here's a code I got from StackOverflow on how to sort dictionary object by value or by key using LINQ in C#. var sortedDict = ( from entry in SortedWebsiteNames orderby entry.Value ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value); var sortedDict = ( from entry in SortedWebsiteNames orderby entry.Value ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value);

AutoComplete Winforms Search Not Working If Search Item Is One Character Digit In C#

Textbox properites: autocompletemode = append, autcompletesource = customsource. Assuming the autocompletestringcollection of the textbox are as follows: James Philipp Mariah Clara 8 Ryan GregEsguerra If you type the number 8 in the textbox, the textbox autocomplete does not suggest. As defined, it will search the prefix of the source. So, i guess one character does not have a prefix at all. The workaround for this is to add a space character after the digit 8. So, "8" becomes "8 ". Below is the code: private void PopulateWebsiteName() { try { if (dtWebsiteNames != null ) { dtWebsiteNames.Clear(); } dtWebsiteNames = JobsReporting.Scripts.GetWebsiteNamesLocal(); if (dtWebsiteNames.Rows.Count > 0) { foreach (DataRow row in dtWebsiteNames.Rows) { if (row[1].ToString().Trim().Length == 1) { row[1] = row[1]

ASP.NET Website Administration (Exception when adding users)

Upon registering new users, I encountered this error upon saving. An error was encountered. Please return to the previous page and try again. The following message may help in diagnosing the problem: Exception has been thrown by the target of an invocation. at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Web.Administration.WebAdminMembershipProvider.CallWebAdminMembershipProviderHelperMeth

Simple Pager Template in ASP.NET Web Forms

Here's a simple pager template in ASP.NET Web Forms. < PagerTemplate > Page: <%= gvPRocess.PageIndex + 1%> of <%= gvPRocess.PageCount %> < asp:button ID = "btnFirst" runat = "server" CommandName = "Page" CommandArgument = "First" Text = "<<" /> < asp:button ID = "btnPrev" runat = "server" CommandName = "Page" CommandArgument = "Prev" Text = "<" /> < asp:button ID = "btnNext" runat = "server" CommandName = "Page" CommandArgument = "Next" Text = ">" /> < asp:button ID = "btnLast" runat = "server" CommandName = "Page" CommandArgument = "Last" Text = ">>" /> </ PagerTemplate >

Donate