Yet another newbie question...
I've been playing with a DGV. Let's say for my question here, I want a grid that is 10x10. I would like the font in each cell to be Arial 10 regular. Only one character will be in each cell (I'll use "M"). I would LIKE the cells to be 17 pixels by 17 pixels. But, if I manually force the column width to be 17, I get about half of my M and three dots "M...". I'm thinking this is a padding thing but as far as I can tell, everything is set to 0. See code and then more comments below:
Question 1: How can I reclaim some of what seems to be lost space around the cell contents so I don't have to make them bigger than they need to be? I'd like them to be 17x17 with the single character centered within.Code:Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load With DataGridView1 .ColumnHeadersVisible = False .RowHeadersVisible = False .AllowUserToResizeColumns = False .AllowUserToResizeRows = False .ColumnCount = 10 .RowCount = 10 '.RowTemplate.Height = 17 'this doesn't seem to do anything .EditMode = DataGridViewEditMode.EditProgrammatically .AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells) .AutoResizeRows(DataGridViewAutoSizeRowsMode.AllCells) .DefaultCellStyle.Font = New Font("Arial", 10, FontStyle.Regular) .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter .DefaultCellStyle.SelectionBackColor = Color.White .DefaultCellStyle.SelectionForeColor = Color.Black End With Dim iR, iC As Integer For iR = 0 To 9 For iC = 0 To 9 DataGridView1(iC, iR).Value = "M" Next Next Dim rowinstance As DataGridViewRow = DataGridView1.Rows(0) 'How do I reference all rows? rowinstance.Height = 17 Dim colinstance As DataGridViewColumn = DataGridView1.Columns(0) 'How do I reference all columns? colinstance.Width = 17 'if I make this less than 20, it messes up the contents. MsgBox("Rows: " & DataGridView1.Rows(1).Height) MsgBox("Columns: " & DataGridView1.Columns(1).Width) End Sub
Question 2: Do I have to manually set the height and width of each row and column? I'm thinking the RowTemplate setting but can't seem to get it to work.
FYI: This is a new project with a DGV dragged onto the form. All changes have been made programatically.
Thanks!





Reply With Quote
