Ace Master Posted November 17, 2003 Posted November 17, 2003 Hi. How I can fill a datagrid from a text file ? I already read the text file into some arrays, and now I want to put them into a data grid, and don't know hot to link the datagrid to my variables. thanks Quote
Pauly Man Posted November 18, 2003 Posted November 18, 2003 I'm having similiar problems, can I ask how you achieved it? Quote
Ace Master Posted November 18, 2003 Author Posted November 18, 2003 I was reading the text file into a array like vect() and this is the code for creating the grid: ' Build the DataSet. m_DataSet = New DataSet("History") ' Build the table. Dim gridul As New DataTable("History") m_DataSet.Tables.Add(gridul) gridul.Columns.Add("Unit ID", GetType(Integer)) gridul.Columns.Add("Unit Name", GetType(String)) gridul.Columns.Add("Unit Value", GetType(String)) gridul.Columns.Add("Date", GetType(String)) ' Populate the History table. Dim grid_data(3) As Object grid_data(0) = 1 grid_data(1) = vect(0) grid_data(2) = vect(1) grid_data(3) = vect(2) gridul.Rows.Add(grid_data) grid_data(0) = 2 grid_data(1) = vect(3) grid_data(2) = vect(4) grid_data(3) = vect(5) gridul.Rows.Add(grid_data) ' Bind the DataGrid to the DataSet. grid.DataSource = m_DataSet if you still have problems, let me know. Quote
Ace Master Posted November 18, 2003 Author Posted November 18, 2003 my problem anybody can tell me how I can make this work ? I have this datagrid and when is opening I want to see the data directly without navigation & stuff ..like in picture 2. thanks Quote
Ace Master Posted November 18, 2003 Author Posted November 18, 2003 this is how I want to look my grid. Quote
Pauly Man Posted November 19, 2003 Posted November 19, 2003 Thanx for the help. I also found a whole load of help in the index which I had never found before. As to your question, I originally had the same problem. I had bound the dataset to the grid, but forgot to tell the grid which datatable I wanted to bind. Which is exactly what you have done. To make the grid also bind to the datatable try this: grid.SetDataBinding(m_DataSet, "History") Where "History" is the name of the DataTable you want to have bound to the grid. As you can see this now tells the grid exactly which dataset, and also which datatable to bind to. Hope it works, it did for me. Quote
Ace Master Posted November 19, 2003 Author Posted November 19, 2003 something else... As you can see in my pictures, I have those columns in equal size. But for ID I don't need to be so big and I want to make a custom column with, but can't find anyware how to do it. Let's say that I want for : ID column : 50px Unit name: 250px Unit Value: 50px Date: 150px how I can make this ?? thanks Quote
Pauly Man Posted November 19, 2003 Posted November 19, 2003 Here is the internet link to the info I have been using, it explains how to alter column width, and almost everything you'd need to alter. :p http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWindowsFormsDataGridClassTopic.asp Also, if you have visual studio.net, or maybe it'll work in visual basic .net, in the index, (choose filtered by Visual Basic), and type in Datagrid control. In the index results double click on the windows forms version of the result. You'll find heaps of info there. But if you want the detailed example scroll down to related sections and click on datagrid class. It's the long way, when you can simply use the above link, but it will work even when you are offline. :D Quote
Ace Master Posted December 16, 2003 Author Posted December 16, 2003 can't find anything there :( ..anyway..something useful. Quote
Mothra Posted December 16, 2003 Posted December 16, 2003 Try this MSDN article. Scroll down to the Table and Column Styles Formatting the DataGrid Quote Being smarter than you look is always better than looking smarter than you are.
Ace Master Posted December 17, 2003 Author Posted December 17, 2003 thanks Mothra. My problem was that I was confusing about name and maping name. now that I put the right maping name...is working well. thanks a lot Quote
Mothra Posted December 17, 2003 Posted December 17, 2003 Not a problem! Quote Being smarter than you look is always better than looking smarter than you are.
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.