WinForm rendering changes when myTableAdapter.Fill() is loaded and display font is 150%

63 Views Asked by At

I have this form that I've been trying to make it work on a display setting set to 150% (Windows 7): enter image description here

I discover that when I comment out "myTableAdapter.Fill();" it works perfectly fine.

private void Form_Load(object sender, EventArgs e)
    {
        //myTableAdapter.Fill(myDatabaseDataSet.myaccessdatabase);
    }

enter image description here

The problem is that I need "myTableAdapter.Fill();" to load in order to be able to get the list of items that will be added to the combobox, but when the table adapter loads, things go a bit out of control (fonts are different sizes and at different places). enter image description here

I know this is NOT a known issue about the combobox showing up at the top left corner of the screen but rather an issue happening when datagridview loads. This ONLY happens when the Display font size is set to 150%.

This is my code:

 private void Form_Load(object sender, EventArgs e)
    {
        myTableAdapter.Fill(myDatabaseDataSet.MyAccessDatabase);

        //fixes the bug that makes the dropdown menus to pop up in the left
        //corner of the screen. This sample if repeats for each 
        //individual combobox...

        var item1 = toolStripComboBox1;
        var createControl1 = item1.Control.Parent.GetType().GetMethod("CreateControl", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
        createControl1.Invoke(item1.Control.Parent, new object[] { true });

             //combobox menustrip code to populate the list of names
             //coming from the access database (in this case for        
             //Managers). It is the same code for "Buyer"; "XP" 
             //and "Aging"...
             for (int intCount = 0; intCount < myDatabaseDataSet.Tables[0].Rows.Count; intCount++)
        {
            var val = myDatabaseDataSet.Tables[0].Rows[intCount][0].ToString();
            if (!toolStripComboBox1.Items.Contains(val))
            {
                toolStripComboBox1.Items.Add(val);
            }
        }
  }

Again, this does not happen when the display font is set to any other percentage. One of my theories is that this part of the code might need some tweaking so it does not cause the combobox to go bersek:

for (int intCount = 0; intCount < myDatabaseDataSet.Tables[0].Rows.Count; intCount++)
        {
            var val = myDatabaseDataSet.Tables[0].Rows[intCount][0].ToString();
            if (!toolStripComboBox1.Items.Contains(val))
            {
                toolStripComboBox1.Items.Add(val);
            }
        }

Is there perhaps an alternative way to load the combobox items where this rendering issue can be avoided?

0

There are 0 best solutions below