Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,156,710 members, 7,831,220 topics. Date: Friday, 17 May 2024 at 03:43 PM

Data Editing Without Graphical Controls - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Data Editing Without Graphical Controls (914 Views)

Adding And Removing Controls Dynamically / Customized Mobile App That Controls A Solar Inverter / Real Time Image Editing (2) (3) (4)

(1) (Reply)

Data Editing Without Graphical Controls by maplecurie: 4:43pm On May 29, 2016
Am new to Dapfor .Net Grid. I want to edit data without graphical controls. Can anyone tell me how I can go about it.
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;
}
}

(1) (Reply)

Internet And Intranet / Web Design, SEO, Graphic Design At Affordable Cost / Reliable Web Solution You Can Trust!

(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.