Try this...
Create Form1, don't change size, add a dataGridView1 and set its anchor to left, top and right, then...
public class Form1 : Form
{
public Form1()
{
InitializeComponent();
dataGridView1.AutoGenerateColumns = true;
var source = new BindingList<Comic>(GetComics());
dataGridView1.DataSource = source;
}
private List<Comic> GetComics()
{
var comics = new List<Comic>();
comics.Add(new Comic() { id = "1", title = "IronMan", editr = "LayneBooks", pages = 65, owned = true });
comics.Add(new Comic() { id = "2", title = "The Hulk", editr = "LayneBooks", pages = 48, owned = false });
comics.Add(new Comic() { id = "3", title = "Superman", editr = "DCCore", pages = 72, owned = true });
return comics;
}
// Custom class, source for grid
private class Comic
{
public string id { get; set; }
public string title { get; set; }
public string editr { get; set; }
public int pages { get; set; }
public bool owned { get; set; }
}
As we know, we can go from cell to cell with arrow keys, or with Tab key (when StandardTab = false
), and reach the grid corners with Ctrl + arrow keys.
Everything is OK with this code, the cells are focused and selected with keys, but when the columns width are manually changed, the not visible cells are focused, but not showed.
For example, using above code, if the width of first and second columns is reduced to a 20 - 30% of its original size, then, the right corner is not reached while pressing Ctrl + right key.
If the third column width is also reduced, and we try to reach the last one with right keys (or Tab), the cell is focused, but not showed completely (or absolutely).
How to solve this?, change columns width and get the same beahviour as when are autogenerated. Is there any property that I am missing?.
My goal is navigate through cells with keys, and show a context menu when Keys.Apps
is pressed, but can't do it if the cell it is not visible.
Thanks!