Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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.

Posted

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

Posted

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.

Posted

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

Posted

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

  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...