How can one change datagridview column width? I have tried the following way but it does not work. Why is it unchanged?
string[] strArrDoctor = new string[] {"ID", "Name", "Specialization", "Contact No", "Experience(Years)", "Delete" };
//strin of array which contains Patient table columns names
string[] strArrPatient = new string[] {"ID", "Name", "Join Date", "Ailment", "Doctor ID", "Delete" };
if (rBtnDoctor.Checked)
{
for (int intIndex = 0; intIndex < dgvShowRecords.Columns.Count; intIndex++)
{
//assigning Column names with our specified String of arrays
dgvShowRecords.Columns[intIndex].HeaderText = strArrDoctor[intIndex];
}
}
else
{
for (int intIndex = 0; intIndex < dgvShowRecords.Columns.Count; intIndex++)
{
dgvShowRecords.Columns[intIndex].HeaderText=strArrPatient[intIndex];
}
}
//dgvShowRecords is Datagridview Name
dgvShowRecords.Columns["Name"].Resizable = DataGridViewTriState.True;
dgvShowRecords.Columns["Name"].Width = 200;
dgvShowRecords.Columns["ID"].Width = 20;
please anyone know reason why it is unchanged let me know.

Try: