Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,823 members, 7,820,891 topics. Date: Wednesday, 08 May 2024 at 12:51 AM

Johnievillie124's Posts

Nairaland Forum / Johnievillie124's Profile / Johnievillie124's Posts

(1) (of 1 pages)

Programming / Headers With Grid by johnievillie124: 4:48pm On May 30, 2016
am new to Dapfor .Net Grid. How can I do headers with grid.
Programming / Re: Data Editing Without Graphical Controls by johnievillie124: 5:00pm On May 29, 2016
maplecurie:
Am new to Dapfor .Net Grid. I want to edit data without graphical controls. Can anyone tell me how I can go about it.

I use dapfor .Net Grid. The following code should be of help.


public class RatingEditor : UITypeEditorEx
{
public override bool GetPaintCellSupported()
{
//The cell should be repainted in the editor
return true;
}

public override void PaintCell(PaintCellEventArgs e)
{
//Do basic painting without text
e.Text = string.Empty;
e.PaintAll();
e.Handled = true;

//Draw the stars over the cell
Rectangle bounds = e.Cell.VirtualBounds;
bounds.Width = Resources.star_grey.Width;
for (int i = 0; i < 5; i++)
{
//Select image
if (e.Cell.Value != null && e.Cell.Value is int)
{
int curRating = (int) e.Cell.Value;
Image image = i >= curRating ? Resources.star_grey : Resources.star_yellow;
e.Graphics.DrawImage(image, bounds);
bounds.X += bounds.Width;
}
}
}

public override StopEditReason EditCell(IGridEditorService service, Cell cell, StartEditReason reason)
{
//Edit the cell if the user has clicked on the cell with the left button
if (cell.Row != null && Equals(StartEditReason.LButtonClick, reason))
{
Point pt = cell.Row.Grid.PointToClient(Cursor.Position);
Rectangle bounds = cell.VirtualBounds;

int imageWidth = Resources.star_grey.Width;
if (bounds.Contains(pt) && imageWidth > 0)
{
//Set a new rating to the data object
cell.Value = ((pt.X - bounds.X)/imageWidth) + 1;
cell.Invalidate();
}
}

return StopEditReason.UserStop;
}
}
Programming / Re: Data Editing In Cells by johnievillie124: 7:01pm On May 24, 2016
maplecurie:
Hello, can someone tell me how i can edit data in cells. I am using .Net grid. thanks



a good question. Dapfor NetGrid expands its features with UITypeEditorEx class. This class has an enhanced set of methods that can be used to create an arbitrary control directly over data cell and to use it for editing.
the code below should be of help.



//This editor creates a clickable button inside the cell
class MyEditor : UITypeEditorEx
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.None;
}

public override StopEditReason EditCell(IGridEditorService service, Cell cell, StartEditReason reason)
{
using(Button button = new Button())
{
//Add a reaction on user click
button.Click += delegate
{
//Close control with some reason
service.CloseCellControl(StopEditReason.UserStop);

//Set a new value if needed
cell.Value = _newvalue_;
};

//Start editing in cell
return service.CellEditControl(button, cell.VirtualBounds, reason);
}
}
}

(1) (of 1 pages)

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 9
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.