DigitalDan3
asked on
Adding a column to a datatable and populating column with default value
I am using the following code to add a column to an existing datatable:
Dim dcStatus As New DataColumn("Status", GetType(String))
m_MissingDocsTable.Columns .Add(dcSta tus)
For i As Integer = 0 To m_MissingDocsTable.Rows.Co unt - 1
Dim dr As DataRow = m_MissingDocsTable.Rows(i)
dr("Status") = "Print"
Next
I am then binding the DataTable to a datagrid. The "Status" Column shows in the grid but the value of each row is null.
What am I doing wrong?
Dan
Dim dcStatus As New DataColumn("Status", GetType(String))
m_MissingDocsTable.Columns
For i As Integer = 0 To m_MissingDocsTable.Rows.Co
Dim dr As DataRow = m_MissingDocsTable.Rows(i)
dr("Status") = "Print"
Next
I am then binding the DataTable to a datagrid. The "Status" Column shows in the grid but the value of each row is null.
What am I doing wrong?
Dan
Try
dcStatus.DefaultValue = "Print"
just before
m_MissingDocsTable.Columns .Add(dcSta tus)
Roger
dcStatus.DefaultValue = "Print"
just before
m_MissingDocsTable.Columns
Roger
ASKER
Grid still returning Null for "Status" Column
Dim dcStatus As New DataColumn("Status", GetType(String))
m_MissingDocsTable.Columns .Add(dcSta tus)
For i As Integer = 0 To m_MissingDocsTable.Rows.Co unt - 1
Dim dr As DataRow = m_MissingDocsTable.Rows(i)
dr("Status") = "Print"
dr.EndEdit()
Next
Me.gridMissingDocs.DataSou rce = MissingDocsTable
Dim dcStatus As New DataColumn("Status", GetType(String))
m_MissingDocsTable.Columns
For i As Integer = 0 To m_MissingDocsTable.Rows.Co
Dim dr As DataRow = m_MissingDocsTable.Rows(i)
dr("Status") = "Print"
dr.EndEdit()
Next
Me.gridMissingDocs.DataSou
ASKER
I added a message box to see what the Value is and it does return "Print"
Dim dcStatus As New DataColumn("Status", GetType(String))
m_MissingDocsTable.Columns .Add(dcSta tus)
For i As Integer = 0 To m_MissingDocsTable.Rows.Co unt - 1
Dim dr As DataRow = m_MissingDocsTable.Rows(i)
dr("Status") = "Print"
dr.EndEdit()
Next
MessageBox.Show(MissingDoc sTable.Row s(0)("Stat us"))
Me.gridMissingDocs.DataSou rce = MissingDocsTable
Dim dcStatus As New DataColumn("Status", GetType(String))
m_MissingDocsTable.Columns
For i As Integer = 0 To m_MissingDocsTable.Rows.Co
Dim dr As DataRow = m_MissingDocsTable.Rows(i)
dr("Status") = "Print"
dr.EndEdit()
Next
MessageBox.Show(MissingDoc
Me.gridMissingDocs.DataSou
Do you have a DataGridTableStyle defined? Are you mapping to the column?
Bob
Bob
ASKER
The Setting of the Default Value worked but why does MessageBox show "Print" but the datagrid shows "Null"
ASKER
I was going to add a TableStyle after I knew the information is correct.
ASKER
I added the tablestyle and it still return null
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Forget the dv.Table line. That was just me experimenting to see if a dataview made any difference.
Roger
Roger
just a question
you are adding a column to table m_MissingDocsTable
but you use a different table for the grid ?
Me.gridMissingDocs.DataSou rce = MissingDocsTable
you are adding a column to table m_MissingDocsTable
but you use a different table for the grid ?
Me.gridMissingDocs.DataSou
For i As Integer = 0 To m_MissingDocsTable.Rows.Co
Dim dr As DataRow = m_MissingDocsTable.Rows(i)
dr("Status") = "Print"
dr.EndEdit()
Next
Bob