how to delete multiple rows having same id in datagridview in visual studio 2010 C# windows from


how delete multiple rows having same id in datagridview in visual studio 2010 c# windows from

hello,

below show how rows via datagridview datasource datatable in button1 while in button2 show how rows via datagridview.datasource need check see if dealing new row.

results code below both buttons

index: 1 first column data: b index: 3 first column data: d index: 1 first column data: b index: 3 first column data: d 

using system; using system.data; using system.linq; using system.windows.forms;  namespace demo {     public partial class form1 : form     {         public form1()         {             initializecomponent();         }          private void form1_load(object sender, eventargs e)         {             datatable dt = new datatable { tablename = "mytable" };              dt.columns.add(new datacolumn { columnname = "column1", datatype = typeof(string) });             dt.columns.add(new datacolumn { columnname = "identifier", datatype = typeof(int) });             dt.columns.add(new datacolumn { columnname = "column3", datatype = typeof(int) });             dt.columns.add(new datacolumn { columnname = "column4", datatype = typeof(int) });              dt.rows.add(new object[] { "a", 15, 1, 0 });             dt.rows.add(new object[] { "b", 10, 2, 0 });             dt.rows.add(new object[] { "c", 9, 3, 0 });             dt.rows.add(new object[] { "d", 10, 1, 1 });             dt.rows.add(new object[] { "e", 22, 3, 1 });             datagridview1.datasource = dt;         }          private void button1_click(object sender, eventargs e)         {             datatable dt = (datatable)datagridview1.datasource;             var drows =                 (                     t in dt.asenumerable().select(                         (row, index) =>                             new                             {                                 data = row,                                 index = index                             }                         )                     t.data.field<int>("identifier") == 10                     select t                 ).tolist();              foreach (var item in drows)             {                 console.writeline("index: {0} first column data: {1}", item.index, item.data.field<string>("column1"));             }         }          private void button2_click(object sender, eventargs e)         {             var drows =                 (                     t in datagridview1.rows.oftype<datagridviewrow>().select(                         (row, index) =>                             new                             {                                 data = row,                                 index = index                             }                         )                     !t.data.isnewrow && convert.toint32(t.data.cells["identifier"].value) == 10                     select t                 ).tolist();              foreach (var item in drows)             {                 console.writeline("index: {0} first column data: {1}", item.index, item.data.cells["column1"].value);             }         }     } }  


please remember mark replies answers if , unmark them if provide no help, others looking solutions same or similar problem.



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'