I have a small program that takes a datatable (takes data from a sql database) then splits it into an array of data by field and then displays it in tabcontrol, each field in its own tab
split, takes a single datatable and splits into a datatable array, works fine, I think
public DataTable[] splitTable(DataTable mainDT,string columnName) { int tmp=0; DataTable[] splitDT = new DataTable[11]; for (int i=0;i<11;i++) splitDT[i]=new DataTable(); foreach (DataRow row in mainDT.Rows) { tmp = row[columnName].GetHashCode(); splitDT[tmp].ImportRow(row); } return splitDT; }
here is the problem
public Display(string Name, string rname, DataTable[] left,int tabNum) { InitializeComponent(); TabPage tp; DataGridView dgw; lLeftTable.Text = Name; for (int i = 0; i < tabNum;i++ ) { tp = new TabPage(""+i); dgw = new DataGridView(); dgw.DataSource = left[i]; tp.Controls.Add(dgw); tbcLeftPages.Controls.Add(tp); tbcLeftPages.Refresh(); } }
it opens a tabcontrol with the desired number of tabs, but there is no data in them
EDIT 1 so far nothing good, show tabs without gridview changed it to a function that receives parts of the data array
public void addDGWtoTab(DataTable dt,string side,int num) { MessageBox.Show("table:" + side + " bucket:" + num + "rows:" + dt.Rows.Count); DataGridView dgw = new DataGridView(); TabPage tp = new TabPage(); //data grid view dgw.Name = "dgv" + num; dgw.AutoSize = true; dgw.Dock = DockStyle.Fill; //tab page tp.Name = "tp" + num; tp.Text = "Bucket " + num; tp.Tag = dt.Rows.Count; tp.TabIndex = num; if (side == "left") tbcLeftPages.Controls.Add(tp); else tbcRightPages.Controls.Add(tp); dgw.DataSource = dt; tp.Controls.Add(dgw); }
EDIT 2 added by spitDT
public DataTable[] splitTable(DataTable mainDT,string columnName,int mod) { DataTable[] splitDT = new DataTable[11]; for (int i=0;i<11;i++) splitDT[i]=new DataTable(); int splitINT; int tmp=0; foreach (DataRow row in mainDT.Rows) { splitINT = row[columnName].GetHashCode(); tmp = splitINT % mod; splitDT[tmp].ImportRow(row); } return splitDT; }
EDIT 3 with post
public DataTable[] splitTable(DataTable mainDT,string columnName,int mod) { DataTable[] splitDT = new DataTable[11]; for (int i=0;i<11;i++) splitDT[i]=new DataTable(); int splitINT; int tmp=0; foreach (DataRow row in mainDT.Rows) { splitINT = row[columnName].GetHashCode(); tmp = splitINT % mod; splitDT[tmp].ImportRow(row); MessageBox.Show("value:" + row[columnName].ToString() + "splitINT:" + splitINT + "mod:" + mod + " to table:" + tmp); MessageBox.Show("" + splitDT[tmp].Rows.Count); } return splitDT; }