c# - How to join two lists and fill a datagridview -
i have 2 list (1st values website, 2nd values .csv file) , i'd join them in list, starting 2 equals values, , display in datagridview.
before post code, i'd tried fill datagridview these 2 lists separately , work.
i didn't error, can't see datagridview values.
i'm going post code , explain it.
first list code:
var url = textbox5.text; //var url = "http://www.betexplorer.com/soccer/norway/tippeligaen/results/"; var web = new htmlweb(); var doc = web.load(url); bets = new list<bet>(); // lettura delle righe var rows = doc.documentnode.selectnodes("//tr"); foreach (var row in rows) { if (!row.getattributevalue("class", "").contains("rtitle")) { if (string.isnullorempty(row.innertext)) continue; var rowbet = new bet(); foreach (var node in row.childnodes) { var data_odd = node.getattributevalue("data-odd", ""); if (string.isnullorempty(data_odd)) { if (node.getattributevalue("class", "").contains("first-cell")) { rowbet.match = node.innertext.trim(); var matchteam = rowbet.match.split(new[] { " - " }, stringsplitoptions.removeemptyentries); rowbet.home = matchteam[0]; rowbet.host = matchteam[1]; } if (node.getattributevalue("class", "").contains("result")) { rowbet.result = node.innertext.trim(); var matchpoints = rowbet.result.split(new[] { ':' }, stringsplitoptions.removeemptyentries); int help; if (int.tryparse(matchpoints[0], out help)) { rowbet.homepoints = help; } if (matchpoints.length == 2 && int.tryparse(matchpoints[1], out help)) { rowbet.hostpoints = help; } } if (node.getattributevalue("class", "").contains("last-cell")) rowbet.date = node.innertext.trim(); } else { rowbet.odds.add(data_odd); } } if (!string.isnullorempty(rowbet.match)) bets.add(rowbet); } }
second list & combined list code:
string filename = @"c:\mydir\testcsv.csv"; oledbconnection conn = new oledbconnection ("provider=microsoft.jet.oledb.4.0; data source = " + path.getdirectoryname(filename) + "; extended properties = \"text;hdr=yes;fmt=delimited\""); conn.open(); oledbdataadapter adapter = new oledbdataadapter ("select * " + path.getfilename(filename), conn); dataset ds = new dataset("temp"); adapter.fill(ds); conn.close(); // datatable dt = new datatable(); datatable dt = ds.tables[0]; //datagridview2.datasource = dt; // datagridview2.datamember = "table"; list<ht> matchlist = new list<ht>(); matchlist = (from datarow dr in dt.rows select new ht() { home = dr["home"].tostring().replace("milan", "ac milan").replace("roma", "as roma"), host = dr["host"].tostring().replace("milan", "ac milan").replace("roma", "as roma"), scorehome = dr["scorehome"].tostring(), scoreaway = dr["scoreaway"].tostring(), //segno = dr["segno"].tostring(), //odd1 = dr["odd1"].tostring(), //oddx = dr["oddx"].tostring(), //odd2 = dr["odd2"].tostring() }).tolist(); // datagridview2.datasource = matchlist; var combineddatalist = (from d1 in bets //join d2 in datalist2 on d1.home equals d2.home join d2 in matchlist on new { d1.home, d1.host } equals new { d2.home, d2.host } select new combineddata { data = d1.date, home = d1.home, away = d1.host, hsft = d1.homepoints, asft = d1.hostpoints, hsht = d2.scorehome, asht = d2.scoreaway, hodd = d1.odd1, xodd = d1.oddx, aodd = d1.odd2, risfin = d1.risfin, over05sh = d1.over05sh, over05ft = d1.over05ft, over15ft = d1.over15ft, over25ft = d1.over25ft, over35ft = d1.over35ft, over45ft = d1.over45ft }).orderby(p => p.hodd); datagridview2.datasource = combineddatalist;
thank attention. have fantastic sunday!
edit: delete unnecessary code
edit2: add screen of single list output. let's see:
second list:
so, i'd merge "scorehome" , "scoreaway" second list in first list based on "home" , "host" have in both lists.
Comments
Post a Comment