jenn5175 Posted July 21, 2003 Posted July 21, 2003 Okay, I realize this is a remedial question but I have been looking for an example on how to use a SQL statement (rather than binding a single table) to generate a datagrid and manually assigning coulmns. The closest example I found for some reason loads the datagrid with a "+" only. When you click the "+" it lists the tables. When I click on a table it expands and I see my data. How can I supass these steps? Here's my main goal in case anyone knows of a good example out there: Join 4 tables in a SQL statement Display roughly 6 columns with my own names (not the field names) and have 1 row display all fields needed (so data from multiple tables) All but one of the columns are read only text/1 column is a checkbox (when checked that row is deleted) I keep finding examples for ASP.NET and VB6 which uses a "Column" type but cannot find anything in VB.NET to allow me to see the columns when it first loads (rather than the "+") and to add my own columns/column names from multiple tables. Is a datagrid even the best choice for what I want to do? Or would I be better off using a different control? Any advice/links would be appreciated - thanks! Jenn Quote
Administrators PlausiblyDamp Posted July 21, 2003 Administrators Posted July 21, 2003 If you are using a dataset for the grid's datasource then it will prompt you with all the datatables it contains. Just point it to the table you want to display i.e. Datagrid1.datasource = ds.Tables("Customers") Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Ariez Posted July 21, 2003 Posted July 21, 2003 Yes, Link to the dataset without specifying any table member. All the tables in the dataset will be accessible. Quote Auto-suggestion: "I have a life" Uncontroled thinking: "So what the.."
jenn5175 Posted July 21, 2003 Author Posted July 21, 2003 PlausiblyDamp - not sure if you quite understood my issue. Say I have three tables: tMainCategories ---------------------- iMainCategoryID sMainCategoryDesc tSubCategories -------------------- iSubCategoryID iMainCategoryID sMainCategoryDesc tEquipmentItems ---------------------- iEquipmentItemID iSubCategoryID sItemDesc Now say in my datagrid I want to display all items along with the main category and sub category it belongs to. In my tEquipmentItems I only have the IDs to those but I want to display the main category description and subcategory description alongside each item. There is not one table in my db that holds all of the information I want to display and therefore I was looking for a way to display a SQL statement rather than a table (so I can join them). I have figured out a way to display a joined SQL statement but cannot figure out how to (a) Name the columns myself (it uses the field name) and (b) Make the columns appear directly on load rather than having to manually click the "+" and then the word "table". Any advice? Jenn Quote
Ariez Posted July 21, 2003 Posted July 21, 2003 YourGatagrid.Expand(-1) opens the + YourGatagrid.Navigate(0, "Table") to open the table of your choice. Quote Auto-suggestion: "I have a life" Uncontroled thinking: "So what the.."
Ariez Posted July 21, 2003 Posted July 21, 2003 Have some adapter get the shema automatically for you with adapter.fill(yourDataset,"Your Table") Edit the relations, it should have hirarchical records in your datagrid... Quote Auto-suggestion: "I have a life" Uncontroled thinking: "So what the.."
thomas10001 Posted July 23, 2003 Posted July 23, 2003 If I understand what you want to do right. Check this link for the solution http://www.codeproject.com/useritems/grid101.asp I had the same problem with having a join in a datagrid and only wanted to show data without the + for navigation. You will have to create and fill an ArrayList from a DataSet and set the ArrayList as the DataSource for the DataGrid. But check the link it has one example in VB which can save the data as well. Also you will create columnstyles which must be mapped to a Property which points out the data in the ArrayList. 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.