Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8174303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:25:04+00:00 2026-06-06T22:25:04+00:00

Let’s say I have a table with a Color column. Color can have various

  • 0

Let’s say I have a table with a Color column. Color can have various values. I have a C# method that can handle items of a given column at a time. Thus, I would like to :

foreach(colorname in mytable.getDistinctColornames)
   monocolorMethod(mytable.getSubTableOnlyContainingRowsWithColor(colorname))

How would I do that elegantly … ?

At all prices, I would avoid copying the data back & forth. I would like kind of a view on the datatable. A view that would only “show” the rows of a given columns, and a “writable” view (i.e. when I write to the filtered subset, the original table is written to)

EDIT :

Let’s say I have a ‘Car’ Table, and I would like to replace ‘Sedan’ by ‘Truck’ in column ‘Type’ for all cars with ‘Color=Red’.

How would I do given the following code ?

DataTable cars (...); // the data

DataView dv = cars.DefaultView;
dv.RowFilter = "Color='Red'";

< Here I would like to loop on the DataView>. The following code does not work :

foreach (row in dv.AsEnumerable)
{
  if(row["Type"] == "Sedan")
    row["Type"] = "Truck";
}

EDIT 2 :

Found this http://msdn.microsoft.com/fr-fr/library/system.data.dataview.allowedit.aspx which suggests

view.AllowEdit = true;
view[0].BeginEdit();
view[0]["FirstName"] = "Mary";
view[0]["LastName"] = "Jones";
view[0].EndEdit();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:25:06+00:00Added an answer on June 6, 2026 at 10:25 pm

    Did you try using DataView class? It looks like exactly what you want to achieve without using LINQ: http://msdn.microsoft.com/en-us/library/fdcwwhez

    An example of usage:

    Let say there is a DataTable object named _dt with 4 rows in it:

    _dt = new DataTable("") {Columns = {new DataColumn("ID"), new DataColumn("Name"), new DataColumn("Order")}};
    _dt.Rows.Add(1, "one", 1);
    _dt.Rows.Add(2, "two", 3);
    _dt.Rows.Add(3, "three", 2);
    _dt.Rows.Add(4, "four", 5);
    

    You can easily create DataView which doesn’t filter data but perform sorting operation on it:

    _dv = new DataView(_dt, "", "Order, Name", DataViewRowState.CurrentRows);
    

    You can also add new rows into the DataView and because it is set on corresponding DataTable that new row will be added directly to _dt object. The sorting order will be updated as well, and new row won’t be the last one within the DataView (because sort is done on Order and Name columns)

    var newRow = _dv.AddNew();
    newRow["ID"] = 5;
    newRow["Name"] = "five";
    newRow["Order"] = 4;
    newRow.EndEdit();
    

    After that code there will be 5 rows in _dt. Editing rows is also quite simple:

    var editedRow = _dv[0];
    editedRow.BeginEdit();
    editedRow["Name"] = "Test";
    editedRow.EndEdit();
    

    You can also use DataView.Find() or DataView.FindRows() methods to find a row within the DataView.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a structure named vertex with a method that adds two
Let's say you have a method that expects a numerical value as an argument.
Let's say I have table with column 'URL' whrere I store urls like this
Let's say that we have an ARGB color: Color argb = Color.FromARGB(127, 69, 12,
Let me explain best with an example. Say you have node class that can
Let's say I can call a method like this: core::get() . What is the
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say I have multiple requirements for a password. The first is that the
Let's say that I have a date in R and it's formatted as follows.
Let's say I have a bunch of links that share a click event: <a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.