private void PaintCell(object sender, MouseEventArgs e) { // Use the HitTest method to get a HitTestInfo object. DataGrid.HitTestInfo hi; DataGrid grid = (DataGrid)sender; hi = grid.HitTest(e.X, e.Y); // Test if the clicked area was a cell. if (hi.Type == DataGrid.HitTestType.Cell) { // If it's a cell, get the GridTable and ListManager of the // clicked table. DataGridTableStyle dgt = dataGrid1.TableStyles[0]; CurrencyManager cm = (CurrencyManager)this.BindingContext[myDataSet.Tables[dgt.MappingName]]; // Get the Rectangle of the clicked cell. Rectangle cellRect; cellRect = grid.GetCellBounds(hi.Row, hi.Column); // Get the clicked DataGridTextBoxColumn. MyGridColumn gridCol = (MyGridColumn)dgt.GridColumnStyles[hi.Column]; // Get the Graphics object for the form. Graphics g = dataGrid1.CreateGraphics(); // Create two new Brush objects, a fore brush, and back brush. Brush fBrush = new System.Drawing.SolidBrush(Color.Blue); Brush bBrush = new System.Drawing.SolidBrush(Color.Yellow); // Invoke the Paint method to paint the cell with the brushes. gridCol.PaintCol(g, cellRect, cm, hi.Row, bBrush, fBrush, false); } }
private void dataGrid1_MouseDown(object sender, MouseEventArgs e) { // Use the HitTest method to get a HitTestInfo object. DataGrid.HitTestInfo hi; DataGrid grid = (DataGrid)sender; hi = grid.HitTest(e.X, e.Y); // Test if the clicked area was a cell. if (hi.Type == DataGrid.HitTestType.Cell) { // If it's a cell, get the GridTable and CurrencyManager of the // clicked table. DataGridTableStyle dgt = dataGrid1.TableStyles[0]; CurrencyManager cm = (CurrencyManager) this.BindingContext[myDataSet.Tables[dgt.MappingName]]; // Get the Rectangle of the clicked cell. Rectangle cellRect = grid.GetCellBounds(hi.Row, hi.Column); // Get the clicked DataGridTextBoxColumn. MyGridColumn gridCol = (MyGridColumn)dgt.GridColumnStyles[hi.Column]; // Edit the value. gridCol.EditCol(cm, hi.Row, cellRect, false, "New Text", true); } }
private void GetHeight() { MyGridColumn myGridColumn = (MyGridColumn)dataGrid1.TableStyles[1].GridColumnStyles[0]; Console.WriteLine(myGridColumn.GetMinHeight()); }