Posts

Donate

Sort Observable Collection Object In WPF

The snippet below sorts the Observable Collection object which is scriptInfo using time_start which is a property of a strongly typed class. scriptInfo.OrderBy(i => i.time_start); Cheers!

WPF Scroll Viewer Slow Performance (Bind Control Height From Another Object Using Code)

In this post, I created a datagrid dynamically or from code. When a record is loaded, the scrolling is slow using Scrollviewer control. So to translate into code behind here's what i come up. Binding bindHeight = new Binding(); bindHeight.ElementName = String.Format( "sizingElement{0}" , index + 1); bindHeight.FallbackValue = 1; bindHeight.Path = new PropertyPath( "ActualHeight" ); //mapGrid is the datagrid object mapGrid.SetBinding(DataGrid.HeightProperty, bindHeight); XAML Markup: <StackPanel x:Name= "spThur" Height= "Auto" Background= "Green" HorizontalAlignment= "Left" Orientation= "Horizontal" > <Rectangle Name= "sizingElement4" Fill= "Transparent" Margin= "1" Height= "333" /> </StackPanel> The mapGrid datagrid is added to the stackpanel. And the Rectangle object is the sizing element.I found the solution from this ...

WPF How To Set Color Value Using Hexademical Value

Here's a snippet that passes a hexa color and set a wpf control object's background/foreground property. BrushConverter bc = new BrushConverter(); Brush brush; brush = (Brush)bc.ConvertFrom( "#003F87" ); notes.SetValue(TextBlock.BackgroundProperty, brush); Original Source:  http://jammer.biz/blog2/?p=169 Greg

Access Datagrid Row In WPF Through Index

Image
Hi All, This is just a repost from this site: Accessing DataGridRow on how to get or access the WPF Datagrid row through index. DataGridRow dgr = (DataGridRow)dataGrid1.ItemContainerGenerator.ContainerFromIndex(nRowIndex); if (dgr == null ) // row might be invisible (top / bottom). So, scroll into the view and get it { dataGrid1.UpdateLayout(); dataGrid1.ScrollIntoView(dataGrid1.Items[nRowIndex]); dgr = (DataGridRow)dataGrid1.ItemContainerGenerator.ContainerFromIndex(nRowIndex); } Thanks for the original contributor, this helped me a lot.

Loop Through Datagrid In WPF (ItemSource Is Type Observable Collection)

Hello, Assuming the databinding source of WPF Datagrid is of type ObservableCollection, the code below will loop through the WPF DataGrid. var row = GetDataGridRows(dgScripts); foreach (DataGridRow r in row) { CScriptsInfo info = (CScriptsInfo)r.Item; if (info.prog_name.ToString().Contains(txtScriptName.Text.Trim().ToUpper())) { r.IsSelected = true ; } }

Count Record In Every Hour Of A Given Day In (MySQL Database

Here is a query to count records gathered in every hour of a given day. The date_visited is a 24 hour time format which is of timestamp data type. The idea came from a fellow developer.. select hour(time(date_visited)) as hour_of_day_24_hour_format, count (hour(time(date_visited))) as count_per_hour from tblpropsale_v2 where date(date_visited) = '2012-05-07' and web_id = 642 and is_visited = 1 group by hour(time(date_visited)) order by hour(time(date_visited)) asc ;

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

I have this string: and the regex has a lazy quantifier to replace the string above to . Using a simple regex pattern, it won't change the string above to ordinary . 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();

Donate