Thursday, August 23, 2012

DataGridviewCell Fore color/Font Weight

Here's the code to apply font weight and font color to your datagridview cell.
Code:
DataGridViewCellStyle style = new DataGridViewCellStyle();  
style.ForeColor = Color.Red;  
style.Font = new Font(this.Font, FontStyle.Bold);  
dg.Rows[dg.Rows.Count - 1].Cells[i + 2].Style = style; 
Greg

Wednesday, August 15, 2012

Check if mouse coordinate is outside the form coordinates in mouseup event

Code:
  private void dgvScriptsTime_MouseUp(object sender, MouseEventArgs e)  
  {  
    if(!this.ClientRectangle.Contains(e.Location))  
    {  
       FShowGrid showGrid = new FShowGrid("Test", dgvScriptsTime);  
       showGrid.ShowDialog();  
    }  
  }

Tuesday, August 14, 2012

Show sql server instances with the network (ASP.NET)

The key is the SqlDataSourceEnumerator to display all instances. You can use gridview or ajax controls for display purposes.
Code:
      protected void Page_Load(object sender, EventArgs e)  
      {  
        // Retrieve the enumerator instance and then the data.  
        SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;  
        System.DataDataTable table = instance.GetDataSources();  
        // Display the contents of the table.  
        DisplayData(table);  
      }  

      private void DisplayData(System.DataDataTable table)  
      {  
        foreach (System.DataDataRow row in table.Rows)  
        {  
          foreach (System.DataDataColumn col in table.Columns)  
          {  
            Response.Write(String.Format("{0} = {1}<br>",  
              col.ColumnName, row[col]));  
          }  
        }  
      } 

Wednesday, August 8, 2012

Save RGB color to SolidBrush object

To save a RGB color to a Solidbrush object, pass the RGB color in the solidbrush constructor.
Code:
olidBrush brush = new SolidBrush(Color.FromArgb(211, 222, 229)); 
Then apply it in your graphics method.
Code:
evs.Graphics.FillRectangle(brush, evs.CellBounds);
Cheers!

Monday, August 6, 2012

Graphic Lines in picture box gone after switching tab pages (C#)

In a program i'm working with, I have a timer event which draws lines or graphs on a picture box. This picture box is inside a tab and panel.

When I switched views to other tabs and return to the tab that has the picture box, the previous lines or graphs disappears. I suspect, the controls are redrawn when switching tabs.

I tried several solutions and options in picture box paint event and infact tried overriding it. Same results.

Luckily, I found a tip in an article to draw the real time graphics on the image itself. This helped solve the issue.

Greg