I’m using Vb.net application program. I created a datagrid having text field and checkbox fields. Everything is displaying correctly. I have 9 Columns and each columns are equally separated. In DataGrid property, I made PreferredColumnWidth = 85. So its equally aligned.
I would like to give more width for the column named Department than rest of the columns. Because when its equally aligned, I can see the Departments displayed.
I’m attaching two pictures with this. “CurrentScreen.bmp” will help you to know how the screen display when page loads. And “NewScreen.bmp” is the way I need to display the screen when page loads.
The code I’m using to display this table is
If you have any idea how to align datagrid, please let me know. If you can provide an example then it will be great help for me.
Thanks in advance.
I would like to give more width for the column named Department than rest of the columns. Because when its equally aligned, I can see the Departments displayed.
I’m attaching two pictures with this. “CurrentScreen.bmp” will help you to know how the screen display when page loads. And “NewScreen.bmp” is the way I need to display the screen when page loads.
The code I’m using to display this table is
VB.NET:
Private Sub MainForm_Load(ByVal …………… ) Handles Me.Load
InitializeDataGrid()
getDepartments()
End Sub
Private Sub InitializeDataGrid()
Dim column1 As DataColumn
MonitorTable1 = New DataTable("MonitorTable")
' Create "Dep ID" column
column1 = New DataColumn("DepID", GetType(Integer))
MonitorTable1.Columns.Add(column1)
' Create "Dep Name" column
column1 = New DataColumn("Department", GetType(String))
MonitorTable1.Columns.Add(column1)
' Create a column for each monitor
For i As Integer = 1 To 7
column1 = New DataColumn("Monitor " & i.ToString(), GetType(Boolean))
column1.AllowDBNull = False
column1.DefaultValue = False
MonitorTable1.Columns.Add(column1)
Next
DataGrid1.DataSource = MonitorTable1
End Sub
Sub getDepartments()
' This is where you might ask the database how many departments there are
MonitorTable1.Rows.Clear()
myConnection.Open()
Dim strSQL As String = "Select DepID, DepName from Dep order by DepName"
Dim myCommand As OleDbCommand = New OleDbCommand(strSQL, myConnection)
Dim myReader As OleDbDataReader = myCommand.ExecuteReader
While myReader.Read
Dim row As DataRow = MonitorTable1.NewRow()
row("DepID") = myReader(0)
row("Department") = myReader(1)
MonitorTable1.Rows.Add(row)
End While
myReader.Close()
myConnection.Close()
DataGrid1.DataSource = MonitorTable1
End Sub
If you have any idea how to align datagrid, please let me know. If you can provide an example then it will be great help for me.
Thanks in advance.