<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Luigi Melisi &#187; GetItemChecked</title>
	<atom:link href="http://www.luigimelisi.com/tag/getitemchecked/feed" rel="self" type="application/rss+xml" />
	<link>http://www.luigimelisi.com</link>
	<description>Development Blog : C# Code Samples,.NET Tips and Tricks</description>
	<lastBuildDate>Sat, 31 Jul 2010 11:07:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>[C#] Determinare elementi spuntati in un controllo CheckedListBox</title>
		<link>http://www.luigimelisi.com/programmazione/net_framework/visual-c/c-determinare-elementi-spuntati-in-un-controllo-checkedlistbox.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=c-determinare-elementi-spuntati-in-un-controllo-checkedlistbox</link>
		<comments>http://www.luigimelisi.com/programmazione/net_framework/visual-c/c-determinare-elementi-spuntati-in-un-controllo-checkedlistbox.html#comments</comments>
		<pubDate>Sun, 15 Nov 2009 10:36:58 +0000</pubDate>
		<dc:creator>Luigi Melisi</dc:creator>
				<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Visual C#]]></category>
		<category><![CDATA[.Net FrameWork]]></category>
		<category><![CDATA[CheckedItems]]></category>
		<category><![CDATA[checkedListBox]]></category>
		<category><![CDATA[GetItemChecked]]></category>

		<guid isPermaLink="false">http://www.luigimelisi.com/?p=334</guid>
		<description><![CDATA[Per la presentazione di dati in un controllo CheckedListBox di Windows Form è possibile scorrere l&#8217;insieme memorizzato nella proprietà CheckedItems o esaminare l&#8217;elenco utilizzando il metodo GetItemChecked per rilevare gli elementi selezionati. Il metodo GetItemChecked accetta il numero di indice di un elemento come argomento e restituisce true o false. Le proprietà SelectedItems e SelectedIndices,]]></description>
			<content:encoded><![CDATA[<p>Per la presentazione di dati in un controllo <span>CheckedListBox</span> di Windows Form è possibile scorrere l&#8217;insieme memorizzato nella proprietà <span><strong>CheckedItems</strong></span> o esaminare l&#8217;elenco utilizzando il metodo <span><strong>GetItemChecked</strong></span> per rilevare gli elementi selezionati. Il metodo <span>GetItemChecked</span> accetta il numero di indice di un elemento come argomento e restituisce <span><span>true</span></span> o <span><span>false</span></span>. <strong>Le proprietà SelectedItems e <span>SelectedIndices</span></strong>, contrariamente a quanto si potrebbe pensare,<strong> non rilevano gli elementi selezionati, ma quelli evidenziati.<br />
Quindi per rilevare gli elementi selezionati in un controllo CheckedListBox :</strong></p>
<ol>
<li>Scorrere l&#8217;insieme <span>CheckedItems</span> partendo da 0, trattandosi di un insieme a base zero. Si noti che il metodo fornirà il numero dell&#8217;elemento nell&#8217;elenco degli elementi selezionati, non nell&#8217;intero elenco. Di conseguenza, se <span id="more-334"></span>il primo elemento dell&#8217;elenco non è selezionato e il secondo sì, nel codice che segue verrà visualizzato un testo analogo a &#8220;Checked Item 1 = MyListItem2&#8243;.</li>
</ol>
<blockquote><p><code><span style="color: green;">// Determina se ci sono elementi spuntati.</span><br />
<span style="color: blue;">if</span>(checkedListBox1.CheckedItems.Count != 0)<br />
{<br />
<span style="color: green;">// If so, loop through all checked items and print results.</span><br />
<span style="color: blue;">string</span> s = <span style="color: maroon;"><span style="color: maroon;">""</span></span>;<br />
<span style="color: blue;">for</span>(<span style="color: blue;">int</span> x = 0; x &lt;= checkedListBox1.CheckedItems.Count - 1 ; x++)<br />
{<br />
s = s + <span style="color: maroon;"><span style="color: maroon;">"Checked Item "</span></span> + (x+1).ToString() + <span style="color: maroon;"><span style="color: maroon;">" = "</span></span> + checkedListBox1.CheckedItems[x].ToString() + <span style="color: maroon;"><span style="color: maroon;">"\n"</span></span>;<br />
}<br />
MessageBox.Show (s);<br />
}</code></p></blockquote>
<p>- oppure -</p>
<ol>
<li>Scorrere l&#8217;insieme <span><strong>Items</strong></span> partendo da 0, trattandosi di un insieme a base zero, e chiamare il metodo <span>GetItemChecked</span> per ogni elemento. Tenere presente che questo metodo fornirà il numero dell&#8217;elemento nell&#8217;intero elenco. Di conseguenza, se il primo elemento dell&#8217;elenco non è selezionato e il secondo sì, verrà visualizzato un testo analogo a &#8220;Item 2 = MyListItem2&#8243;.</li>
</ol>
<blockquote><p><code><span style="color: blue;">int</span> i; <span style="color: blue;">string</span> s;<br />
s = <span style="color: maroon;"><span style="color: maroon;">"Checked items:\n"</span></span> ;<br />
<span style="color: blue;">for</span> (i = 0; i &lt;= (checkedListBox1.Items.Count-1); i++)<br />
{<br />
<span style="color: blue;">if</span> (checkedListBox1.GetItemChecked(i))<br />
{<br />
s = s + <span style="color: maroon;"><span style="color: maroon;">"Item "</span></span> + (i+1).ToString() + <span style="color: maroon;"><span style="color: maroon;">" = "</span></span> + checkedListBox1.Items[i].ToString() + <span style="color: maroon;"><span style="color: maroon;">"\n"</span></span>;<br />
}<br />
}<br />
MessageBox.Show (s);</code></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.luigimelisi.com/programmazione/net_framework/visual-c/c-determinare-elementi-spuntati-in-un-controllo-checkedlistbox.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
