🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.pl.comp.lang.csharp
Article #22253

Wywołanie funkcji z Event'u komórki SourceGrid'a

#22253
From: saper/nolin11
Date: Tue, 13 Sep 2011 20:34
95 lines
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
Technical Details
Message-ID: <j4oeol$89r$1@news.dialog.net.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.dialog.net.pl!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.dialog.net.pl!not-for-mail
From: saper/nolin11 <nolinno11_usun_to@gmail.com>
Newsgroups: alt.pl.comp.lang.csharp
Subject: Wywołanie funkcji z Event'u
 komórki SourceGrid'a
Date: Tue, 13 Sep 2011 22:34:26 +0200
Organization: Dialog Net
Lines: 95
Message-ID: <j4oeol$89r$1@news.dialog.net.pl>
NNTP-Posting-Host: dynamic-78-8-56-157.ssp.dialog.net.pl
Mime-Version: 1.0
X-Trace: news.dialog.net.pl 1315946070 8507 78.8.56.157 (13 Sep 2011 20:34:30 GMT)
X-Complaints-To: abuse@dialog.net.pl
NNTP-Posting-Date: Tue, 13 Sep 2011 20:34:30 +0000 (UTC)
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2
X-Antivirus: avast! (VPS 110913-1, 2011-09-13), Outbound message
X-Antivirus-Status: Clean
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit