Thread View: alt.pl.comp.lang.csharp
2 messages
2 total messages
Started by saper/nolin11
Tue, 13 Sep 2011 20:34
Wywołanie funkcji z Event'u komórki SourceGrid'a
Author: saper/nolin11
Date: Tue, 13 Sep 2011 20:34
Date: Tue, 13 Sep 2011 20:34
95 lines
3537 bytes
3537 bytes
Witam,
Prawdopodobnie banalne wyjście z tego ale nie wiem jak :(, otóż mam na
formie SourceGrid i do każdego Cell'a przypięty event OnClik, oczywiście
zdarzenia na bazie przykładów od komponentu. I nie wiem jak wywołać
funkcję UpdateGrid() z funkcji zdarzenia klasy eventu (o matko jak to
brzmi :) ), trochę kodu (wszystko jest częścią klasy formy (WinForms)):
[code]
/// <summary>
/// Setup grid
/// </summary>
private void SetGrid()
{
// set new grid size
grid1.Redim(Convert.ToInt32(eHeight.Value), Convert.ToInt32(eWidth.Value));
// click event
CellClickEvent cke = new CellClickEvent();
SourceGrid.Cells.Views.Cell vWh = new SourceGrid.Cells.Views.Cell();
vWh.BackColor = Color.White;
vWh.ForeColor = Color.White;
// Create cells
for (int y = 0; y < Convert.ToInt32(eHeight.Value); y++)
for (int x = 0; x < Convert.ToInt32(eWidth.Value); x++)
{
grid1[y, x] = new SourceGrid.Cells.Cell("0");
grid1[y, x].Column.Width = colWidth;
grid1[y, x].Row.Height = colHeight;
grid1[y, x].AddController(cke);
grid1[y, x].View = vWh;
}
UpdateGrid();
}
/// <summary>
/// Update cells colors basing on cell value (0 - white, 1-black)
/// </summary>
public void UpdateGrid()
{
textBox1.Clear();
SourceGrid.Cells.Views.Cell vWh = new SourceGrid.Cells.Views.Cell();
vWh.ForeColor = Color.White;
vWh.BackColor = Color.White;
SourceGrid.Cells.Views.Cell vBk = new SourceGrid.Cells.Views.Cell();
vBk.ForeColor = Color.Black;
vBk.BackColor = Color.Black;
for (int y = 0; y < grid1.RowsCount; y++)
for (int x = 0; x < grid1.ColumnsCount; x++)
{
if ((string)grid1[y, x].Value == "1") grid1[y, x].View = vBk;
else grid1[y, x].View = vWh;
}
grid1.Refresh();
UpdateFontPicture();
}
/// <summary>
/// SourceGrid.Grid cells events
/// </summary>
public class CellClickEvent : SourceGrid.Cells.Controllers.ControllerBase
{
public override void OnMouseDown(SourceGrid.CellContext sender,
MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
if ((string)sender.Value == "0") sender.Value = "1";
else sender.Value = "0";
}
base.OnMouseDown(sender, e);
}
public override void OnKeyDown(SourceGrid.CellContext sender,
KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
if ((string)sender.Value == "0") sender.Value = "1";
else sender.Value = "0";
// Z tego miejsca chcę wywołać moje: UpdateGrid()
}
base.OnKeyDown(sender, e);
}
}
[/code]
--
Saper/nolin11
nolinno11_usun_to@gmail.com
gg:4476700
Re: Wywołanie funkcji z Event'u komórki SourceGrid'a
Author: Łukasz 'Maly' Ostrowski
Date: Wed, 14 Sep 2011 08:11
Date: Wed, 14 Sep 2011 08:11
54 lines
2353 bytes
2353 bytes
On Tue, 13 Sep 2011 22:34:26 +0200, saper/nolin11 wrote:
> Witam,
>
> Prawdopodobnie banalne wyjście z tego ale nie wiem jak :(, otóż mam na
> formie SourceGrid i do każdego Cell'a przypięty event OnClik, oczywiście
> zdarzenia na bazie przykładów od komponentu.
Przypnij kontroler do grida zamiast do indywidualnych celli. Stanowczo
łatwiej.
> I nie wiem jak wywołać
> funkcję UpdateGrid() z funkcji zdarzenia klasy eventu (o matko jak to
> brzmi :) ), trochę kodu (wszystko jest częścią klasy formy (WinForms)):
Zakładając że masz:
class WhateverForm : Form
{
void UpdateGrid();
...
}
> /// <summary>
> /// SourceGrid.Grid cells events
> /// </summary>
> public class CellClickEvent : SourceGrid.Cells.Controllers.ControllerBase
> {
WhateverForm form;
public CellClickEvent(WhateverForm form)
{
this.form = form;
}
> public override void OnKeyDown(SourceGrid.CellContext sender,
> KeyEventArgs e)
> {
> if (e.KeyCode == Keys.Space)
> {
> if ((string)sender.Value == "0") sender.Value = "1";
> else sender.Value = "0";
> // Z tego miejsca chcę wywołać moje: UpdateGrid()
form.UpdateGrid();
> }
> base.OnKeyDown(sender, e);
> }
> }
> [/code]
P.S. możesz zmieniać kolor w Controller.OnValueChanged zamiast
za każdym razem iterować po całym gridzie.
--
Pozdrawiam,
Łukasz 'Maly' Ostrowski. http://l3v.eu/
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads