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.
Department is the second column. that having long names under that. so when page loads, its only displaying half of that. so if i increase that column width i can see that. but i don't need to increase the other columns width. make rest of the columns width smaller and increase the second columns width.
The code Iâm using to display this table is
Code:
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.