data editing without graphical controls

Posted by Maplecurie under C# on 5/24/2016 | Points: 10 | Views : 316 | Status : [Member] | Replies : 1
Am new to Dapfor .Net Grid. I want to edit data without graphical controls. Can anyone tell me how I can go about it.




Responses

Posted by: Sobort84 on: 5/24/2016 [Member] Starter | Points: 25

Up
0
Down
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;
}
}


Maplecurie, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response