After a little investigation, I found the answer for this.
I am setting a data source in a combobox column in a datagridview. So, after setting the data source, I find the width of the largest element in the datatable for the value that is set as the DisplayMember column. I use the same logic that was mentioned in the link above in my question, instead of doing it in a DropDown event, I do this by setting the data source that was at the same time. In the link above, in my question, the width of the drop-down list was indicated for each drop-down list. So my approach looks good.
Here is how I did it:
// This line is picked up from designer file for reference
DataGridViewComboBoxColumn CustomerColumn;
DataTable _customersDataTable = GetCustomers();
CustomerColumn.DataSource = _customersDataTable;
CustomerColumn.DisplayMember = Customer_Name;
CustomerColumn.ValueMember = ID;
var graphics = CreateGraphics();
// Set width of the drop down list based on the largest item in the list
CustomerColumn.DropDownWidth = (from width in
(from DataRow item in _customersDataTable.Rows
select Convert.ToInt32(graphics.MeasureString(item[Customer_Name].ToString(), Font).Width))
select width).Max();
source
share