Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Articles
Search: 

Bonnie Berent's Tips
Bonnie DeWitt, February 1, 2007
Great tips for .NET developers.
Summary
Great tips for .NET developers.
Description

Active Configuration
Is there a way via code to determine what the current Configuration Setting is (ie: Debug, Release, or CustomMade config)? The answer, of course, is yes:
    Dim objDTE As EnvDTE.DTE
    objDTE = System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE")

    MessageBox.Show(objDTE.Solution.SolutionBuild.ActiveConfiguration.Name)
In C#, you'll have to cast to EnvDTE.DTE:
    EnvDTE.DTE objDTE;
    objDTE = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE");

    MessageBox.Show(objDTE.Solution.SolutionBuild.ActiveConfiguration.Name);
You'll also have to add a reference in your project to EnvDTE.

from a solution provided by Ben Santiago in Message #1105962

Filtering/Selecting data in ADO.NET
ADO.NET provides two different ways to filter data: either using a DataView and a RowFilter, or using a DataTable.Select().

Here are some examples of a DataView/RowFilter - you can essentially define a custom "view" of a datatable, based on a filter criteria, and then iterate through the items in the view:

string cFilter;     // Examples of RowFilter
cFilter = " Amount > 1000 ";
cFilter = "FirstName = 'Ken' OR EmpFlag = true";
cFilter = " City LIKE '%whatever%' ";
cFilter = "EmployeeID IN (12,144,54)";

// This one assumes a Parent Relation....it's to demonstrate that if you have an ADO.NET relation,
//  you can specify Parent/Child syntax
cFilter = "Parent(RelName) = 'National'";

string cSort = "Location ASC, Salary DESC";

DataView Dv = new DataView(MyTable, cFilter, cSort, DataViewRowState.CurrentRows);
// you can now iterate through the items in the Dv Collection
foreach(DataRowView drv in Dv)
   ...
You can also use a DataTable.Select(). The results of a DataTable.Select() are a collection of DataRow objects. You can use the same filter and sort syntax as you used for a DataView:
DataRow[] aRows = MyTable.Select(cFilter,cSort);
foreach(DataRow oRow in aRows)
   // process the oRow object, using the column objects for the row

Typically you'll want to use the dataview/rowfilter when you want to bind the results to a control that's capable of reading a dataview. Use DataTable.Select() when you want to manually loop through the resulting rows.

If you have a table with a primary key, you can do an ADO.NET FIND (similar to a SEEK)

MyDataTable.PrimaryKey = new DataColumn[] {MyDataTable.Columns["MyPrimaryKey"]};
DataRow dr = MyDataTable.Find(111);
Here are two of Kevin's articles in CoDe magazine that cover some of these ADO.NET topics.

http://www.code-magazine.com/Article.aspx?quickid=0601031

http://www.code-magazine.com/Article.aspx?quickid=0607061

from a solution provided by Kevin Goff in Message #1142200

ASP.NET Dynamic Grid Colors
To dynamically change your ASP.NET GridView's color, try something like this:
    protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            switch(DataBinder.Eval(e.Row.DataItem, "Team").ToString().Trim())
            {
            case "1":
                e.Row.BackColor = System.Drawing.Color.BurlyWood;
                break;
            case "2":
                e.Row.BackColor = System.Drawing.Color.Red;
                break;
            }
        }
    }

from a solution provided by David Smith in Message #1111507

Using a WinForm DataGrid for Navigation
How can you use a WinForm DataGrid (or a DataGridView) for navigation?

Say a user clicks on a row in a DataGrid to indicate that this is the row that they'd like to edit on a detail page. How can you "select" that Row to present the user with the detail page?

Try using the HitTest() method in an event like the MouseDown:

private void MouseDownHandler(object sender, MouseEventArgs e)
{
    System.Windows.Forms.DataGrid.HitTestInfo myHitTest = this.HitTest(e.X, e.Y);
    if (myHitTest.Type == System.Windows.Forms.DataGrid.HitTestType.Cell)
    {
        // myHitTest.Row will contain the index of the row in the DataTable.
    }
}

from a solution provided by Bonnie Berent in Message #1147472

Bonnie DeWitt, Geneva Systems Group
Bonnie is currently one of the principals of Geneva Systems Group. Call her the Senior Software Engineer, or even call her the VP of Engineering. She has no official title at the moment. Bonnie has been writing software in various languages for about 30 years. Bonnie's current focus on C# .NET applications began in early 2002. She has been a Microsoft C# MVP since Oct 2003 and an active member of the .NET online community.
More articles from this author
Bonnie DeWitt, September 1, 2005
Great tips for .NET developers
Bonnie DeWitt, October 1, 2005
Great tips for .NET developers
Bonnie DeWitt, November 1, 2005
Great tips for .NET developers
Bonnie DeWitt, December 1, 2005
Great tips for .NET developers
Bonnie DeWitt, April 1, 2009
Great tips from the .NET developer community compiled by Bonnie Berent.
Bonnie DeWitt, February 1, 2006
Great tips for .NET developers
Bonnie DeWitt, March 1, 2006
Great tips for .NET developers
Bonnie DeWitt, April 1, 2006
Great tips for .NET developers
Bonnie DeWitt, May 1, 2006
Great tips for .NET developers
Bonnie DeWitt, June 1, 2006
Great tips for .NET developers
Bonnie DeWitt, July 1, 2006
Great tips for .NET developers
Bonnie DeWitt, August 1, 2006
Great tips for .NET developers
Bonnie DeWitt, September 1, 2006
Great tips for .NET developers
Bonnie DeWitt, October 1, 2006
Great tips for .NET developers
Bonnie DeWitt, November 1, 2006
Great tips for .NET developers
Bonnie DeWitt, December 1, 2006
Great tips for .NET developers
Bonnie DeWitt, January 1, 2007
Great tips for .NET developers
Bonnie DeWitt, March 1, 2006
Great tips for .NET developers.
Bonnie DeWitt, April 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, March 1, 2007
Good tips for .NET developers.
Bonnie DeWitt, May 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, June 1, 2007
Great tips and tricks for .NET developers.
Bonnie DeWitt, July 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, August 1, 2007
Great tips for .NET developers
Bonnie DeWitt, September 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, February 1, 2008
Great tips from the Universal Thread .NET community.
Bonnie DeWitt, March 1, 2008
Great tips for .NET developers selected from the community by Bonnie Berent.
Bonnie DeWitt, April 1, 2008
Great tips from the .NET developer community compiled by Bonnie Berent.
Bonnie DeWitt, January 1, 2006
Great tips for .NET developers