DataGridViewRow.GetPreferredHeight Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menghitung tinggi ideal baris yang ditentukan berdasarkan kriteria yang ditentukan.
public:
virtual int GetPreferredHeight(int rowIndex, System::Windows::Forms::DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth);
public virtual int GetPreferredHeight(int rowIndex, System.Windows.Forms.DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth);
abstract member GetPreferredHeight : int * System.Windows.Forms.DataGridViewAutoSizeRowMode * bool -> int
override this.GetPreferredHeight : int * System.Windows.Forms.DataGridViewAutoSizeRowMode * bool -> int
Public Overridable Function GetPreferredHeight (rowIndex As Integer, autoSizeRowMode As DataGridViewAutoSizeRowMode, fixedWidth As Boolean) As Integer
Parameter
- rowIndex
- Int32
Indeks baris yang tinggi pilihannya dihitung.
- autoSizeRowMode
- DataGridViewAutoSizeRowMode
DataGridViewAutoSizeRowMode yang menentukan mode ukuran otomatis.
- fixedWidth
- Boolean
true untuk menghitung tinggi pilihan untuk lebar sel tetap; jika tidak, false.
Mengembalikan
Tinggi baris yang ideal, dalam piksel.
Pengecualian
autoSizeRowMode bukan nilai yang valid DataGridViewAutoSizeRowMode .
rowIndex tidak dalam rentang valid 0 hingga jumlah baris dalam kontrol minus 1.
Contoh
Contoh kode berikut menggunakan GetPreferredHeight metode untuk menentukan padding baru untuk baris yang telah diubah ukurannya. Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan dalam Cara: Menyesuaikan Tampilan Baris di Kontrol DataGridView Formulir Windows.
// Adjusts the padding when the user changes the row height so that
// the normal cell content is fully displayed and any extra
// height is used for the content that spans multiple columns.
void dataGridView1_RowHeightChanged(object sender,
DataGridViewRowEventArgs e)
{
// Calculate the new height of the normal cell content.
Int32 preferredNormalContentHeight =
e.Row.GetPreferredHeight(e.Row.Index,
DataGridViewAutoSizeRowMode.AllCellsExceptHeader, true) -
e.Row.DefaultCellStyle.Padding.Bottom;
// Specify a new padding.
Padding newPadding = e.Row.DefaultCellStyle.Padding;
newPadding.Bottom = e.Row.Height - preferredNormalContentHeight;
e.Row.DefaultCellStyle.Padding = newPadding;
}
' Adjusts the padding when the user changes the row height so that
' the normal cell content is fully displayed and any extra
' height is used for the content that spans multiple columns.
Sub dataGridView1_RowHeightChanged(ByVal sender As Object, _
ByVal e As DataGridViewRowEventArgs) _
Handles dataGridView1.RowHeightChanged
' Calculate the new height of the normal cell content.
Dim preferredNormalContentHeight As Int32 = _
e.Row.GetPreferredHeight(e.Row.Index, _
DataGridViewAutoSizeRowMode.AllCellsExceptHeader, True) - _
e.Row.DefaultCellStyle.Padding.Bottom()
' Specify a new padding.
Dim newPadding As Padding = e.Row.DefaultCellStyle.Padding
newPadding.Bottom = e.Row.Height - preferredNormalContentHeight
e.Row.DefaultCellStyle.Padding = newPadding
End Sub
Keterangan
Properti ini digunakan oleh fitur ukuran otomatis berbasis konten kontrol DataGridView untuk menentukan tinggi baris yang ideal. Nilai memungkinkan rowIndex Anda menentukan indeks baris aktual dari baris bersama. (Baris bersama memiliki Index nilai properti -1.)
fixedWidth Nilai false parameter menghitung tinggi baris berdasarkan lebar kolom terhitung yang akan mencapai rasio tinggi hingga lebar sel yang ideal.
Agar konten sel dibungkus ke beberapa baris, gaya sel yang berlaku untuk sel harus memiliki WrapMode nilai Trueproperti .
Untuk informasi selengkapnya tentang ukuran otomatis, lihat Opsi Ukuran di Kontrol Windows Forms DataGridView.
Berlaku untuk
Lihat juga
- DataGridView
- DataGridViewAutoSizeRowMode
- WrapMode
- GetPreferredWidth(DataGridViewAutoSizeColumnMode, Boolean)
- Cara: Menyesuaikan Tampilan Baris di Kontrol Windows Forms DataGridView
- Opsi Ukuran di Kontrol Windows Forms DataGridView
- Praktik Terbaik untuk Menskalakan Kontrol DataGridView Formulir Windows