Drizzt109 Posted July 14, 2004 Posted July 14, 2004 once I run my SQL query and load the data table, it says there are no columns in the Columns collection, even though I can see data in the grid. How is this possible? dt.Columns.Count.ToString() returns 0. So there's no way for me to bind a DataGridColumnStyle to any particlular column... Quote
Drizzt109 Posted July 15, 2004 Author Posted July 15, 2004 maybe this will help? Thanks! private void Form1_Load(object sender, System.EventArgs e) { InitializeCombos(); t.Elapsed+=new System.Timers.ElapsedEventHandler(ChangeTextBox); t.AutoReset = true; t.Enabled = true; loadCSVFile(); CreateGrid(); AddStyle(); rt = new Realtick.RealtickClass(); rt.BalanceUpdate = 1; rt.TradeUpdate = 1; order = new Order(rt,this); MessageBox.Show (dt.Columns.Count.ToString()); } private void loadCSVFile() { try { string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\;Extended Properties = Text;"; OleDbConnection objConn; OleDbCommand objCmdSelect; OleDbDataAdapter objAdapter1; objConn = new OleDbConnection(sConnectionString); objConn.Open(); objCmdSelect = new OleDbCommand("SELECT * FROM test1.csv",objConn); objAdapter1 = new OleDbDataAdapter(); objAdapter1.SelectCommand = objCmdSelect; objAdapter1.Fill(ds); objConn.Close(); } catch(Exception e) { Console.Write(e.Message); } } public void CreateGrid() { dataGrid1.DataSource = ds.Tables[0].DefaultView; dt = ds.Tables.Add("MyTable"); aColStr[0] = "Ticket ID"; aColStr[1] = "Symbol"; aColStr[2] = "Side"; //dt.Columns.Add(aColStr[0].ToString(),typeof(string)); //dt.Columns.Add(aColStr[1].ToString(), typeof(string)); //dt.Columns.Add(aColStr[2].ToString(),typeof(string)); //dt.Columns.Add("Volume", typeof(short)); //dt.Columns.Add("Route", typeof(string)); //dt.Columns.Add("Status",typeof(string)); } public void AddStyle() { DataGridTableStyle dgTableStyle = new DataGridTableStyle(); dgTableStyle.MappingName = dt.TableName;//its table name of dataset DataGridTextBoxColumn symbolCol = new DataGridTextBoxColumn(); symbolCol.MappingName = aColStr[0]; symbolCol.HeaderText = "SYMBOL"; symbolCol.Width = 200; dgTableStyle.GridColumnStyles.Add(symbolCol); dataGrid1.TableStyles.Add(dgTableStyle); GridColumnStylesCollection colStyle; colStyle = dataGrid1.TableStyle[0].GridColumnStyles; //colStyle[0].Width = 100; //colStyle[1].Width = 100; //colStyle[2].Width = 100; //datagridTextBox = new DataGridTextBoxColumn(dataGrid1.TableStyles[0].GridColumnStyles[0]); } Quote
ost Posted July 16, 2004 Posted July 16, 2004 try something like this //connect to csv and fill dataset string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\;Extended Properties = Text;"; OleDbConnection objConn; OleDbCommand objCmdSelect; OleDbDataAdapter objAdapter1; objConn = new OleDbConnection(sConnectionString); objConn.Open(); objCmdSelect = new OleDbCommand("SELECT * FROM csvTest.txt", objConn); objAdapter1 = new OleDbDataAdapter(); objAdapter1.SelectCommand = objCmdSelect; objAdapter1.Fill(ds); objConn.Close(); //Name the datacolumn ds.Tables(0).Columns(0).ColumnName = "MobileNo"; //create tablestyle and add it to datagrid DataGridTableStyle tableStyle = new DataGridTableStyle(); tableStyle.MappingName = "table"; DataGridTextBoxColumn column = new DataGridTextBoxColumn(); column.MappingName = "MobileNo"; column.HeaderText = "MobileNo"; column.Width = 100; tableStyle.GridColumnStyles.Add(column); this.DataGrid1.TableStyles.Add(tableStyle); //make the dataset the datasource of the datagrid this.DataGrid1.DataSource = ds.Tables(0); MsgBox(ds.Tables(0).Columns.Count()); Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.