How to fill a datagrid with non database data?

Results 1 to 2 of 2

Thread: How to fill a datagrid with non database data?

  1. #1
    Join Date
    Dec 1969

    Default How to fill a datagrid with non database data?

    I want to create a table with data that doesn&#039;t come from a database, but generated from userinput.<BR><BR>Is it possible to use a datagrid to create a table where I can select which data to appear in row x, column y? And if it&#039;s possible, can you give me an example of how to do so?<BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: How to fill a datagrid with non database data?

    You can solve the problem by creating a datatable and set the datatable as source of the datagrid. Here i am providing some sample code to create a datatable and populating data.<BR><BR>Dim dtAdvice As DataTable<BR>Dim dtColumn As DataColumn<BR> dtColumn = New DataColumn("Col1", GetType(String))<BR> dtAdvice.Columns.Add(dtColumn)<BR> dtColumn.AutoIncrement = True<BR> dtColumn.AutoIncrementSeed = 1<BR> dtColumn = New DataColumn("Col2", GetType(String))<BR> dtAdvice.Columns.Add(dtColumn)<BR> dtColumn = New DataColumn("Col3", GetType(String))<BR> dtAdvice.Columns.Add(dtColumn)<BR> dtColumn = New DataColumn("Col14", GetType(String))<BR> dtAdvice.Columns.Add(dtColumn)<BR> dtColumn = New DataColumn("Col5", GetType(String))<BR> dtAdvice.Columns.Add(dtColumn)<BR><BR>The above code creates a datatable called dtAdvice and col1 is the auto increment column(you can use this column as primary key if you want)<BR><BR>Dim dtRow As DataRow<BR><BR>dtRow = dtAdvice.NewRow()<BR> dtRow("Col2") = val1(Replace this with values)<BR> dtRow("Col3") = ""<BR> dtRow("Col4") = ""<BR> dtRow("Col5") = ""<BR><BR> dtAdvice.Rows.Add(dtRow)<BR><BR>The above code populates data.<BR><BR>Set dtAdvice As source of the datagrid. I hope that the above code will solve your problem. If not let me know<BR><BR>Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts