Geekpedia Tutorials Home

Building a C# Chat Client and Server

Building a C# Chat Client and ServerA step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.

in C# Programming Tutorials

Getting Hard Drive Information

Getting Hard Drive InformationA C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.

in C# Programming Tutorials

UPS Shipping Calculator

UPS Shipping CalculatorThis tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.

in PHP Programming Tutorials

Create Your Own Rich Text Editor

Create Your Own Rich Text EditorCreating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.

in JavaScript Programming Tutorials
Search
Tutorials
Programming Tutorials
IT Jobs
From CareerBuilder

ListBox and CheckedListBox

Here we'll cover the aspects of C#'s list boxes and checked list boxes (ListBox and CheckedListBox controls).

On Saturday, May 8th 2004 at 07:41 PM
By Andrew Pociu (View Profile)
*****   (Rated 4.5 with 85 votes)
Contextual Ads
More C# Resources
Advertisement

Using the ListBox



We'll start with a 'Windows Application' project in Microsoft Visual C# .NET. Name it 'ListBoxes'.
To your newly created form add from the Toolbox a ListBox named 'itemList', a TextBox named itemName and three buttons named 'cmdAdd', 'cmdRem' and 'cmdClr'.

Your form should now look similar to this one:



All the action is started by the last 3 buttons we have added, of course.
New items can be added to the list by the programmer by selecting the list box and using the 'Items' property.



A window pops up, where you can enter new items to be displayed in the list box. Each line represents a new item.

Now arrives the important part: coding. We'll use the Click event of the 'cmdAdd' button to add new items to the list. Of course, the name of the item will be the text in the 'itemName' text box.

Double click the 'cmdAdd' button to get into the cmdAdd_Click event directly and use the following code:


private void cmdAdd_Click(object sender, System.EventArgs e)
{
    if(itemName.Text == "")
    {
        MessageBox.Show("Please enter a name.", "No name entered", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    }
    else
    {
        itemList.Items.Add(itemName.Text);
    }
}



As you can see we first test to see if the text box in which the name of the item to be added to the list has any value at all.
If it doesn't (it is equal to "" - that is nothing) we popup an exclamation MessageBox with an OK button that asks the user to enter a name first.



If it has a value, the item is added to the list by using the 'Add()' method of the 'Items' collection.

The remove button acts similar.


private void cmdRem_Click(object sender, System.EventArgs e)
{
    if(itemList.SelectedIndex == -1)
    {
        MessageBox.Show("Please select an item first.", "No item selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    }
    else
    {
             itemList.Items.RemoveAt(itemList.SelectedIndex);
    }
}



What does


if(itemList.SelectedIndex == -1)



actually do, you ask?

Every item in a list box has an index. The SelectedIndex property shows us which item is currently selected in the list box. If no item is selected the SelectedIndex property is set to -1.
We want to assure that an item is selected before trying to remove it, don't we?
This is why if no item is selected (SelectedIndex equals -1) we warn the user.



If there is an item selected we can safely remove it using 'Items.RemoveAt()' and passing the index of the selected item using 'itemList.SelectedIndex' property.

Finaly, we clear the list box using:


private void cmdClr_Click(object sender, System.EventArgs e)
{
    itemList.Items.Clear();
}



As you just saw, handling list boxes isn't so hard.

Using the CheckedListBox



Similar to its base class, ListBox but allows items to be checked using the checkbox next to each item, this way you can select multiple items.

Create a new project named 'CheckedListBoxes' and add to it a CheckedListBox and a ListBox. Name them 'checkedList' and 'selectedList'. Now add some items to checkedList (you can add new items just like you do when using a simple ListBox - from Properties choose Items, in the window that pops up every line represents a new item).
After you add some items to 'checkedList' your form should look similar to this:



We want every item that is checked in 'checkedList' to be added to the 'selectedList'.
This is easy to code by using the 'ItemCheck' event of our CheckedListBox.
With our CheckedListBox ('checkedList') selected go to the Events section and scroll until you find the ItemCheck event.



Double click the empty box next to ItemCheck. Microsoft Visual C# will automatically add the 'checkedList_ItemCheck' next to ItemCheck and the Event window will now look like in the picture above. Also Visual Studio will bring you to the part where you need to code:


private void checkedList_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
{

}



The ItemCheck event occurs when a value is checked or unchecked in the CheckedListBox. We can use this to add checked items to 'selectedList' and remove them from there when they are unchecked.
We can use this code:


private void checkedList_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
{
    if( e.NewValue == CheckState.Checked)
    {
    selectedList.Items.Add(checkedList.SelectedItem.ToString());
    }
    else
    {
    selectedList.Items.Remove(checkedList.SelectedItem.ToString());
    }
}


First we check to see the NewValue of the changed item represented by the 'e' argument. If its CheckState is Checked we can add it to the list by using the selectedList.Items.Add() method we learned earlier about.
We also need to convert the SelectedItem using ToString().
Else, if the item was unchecked we remove it in a manner similar to the one we used to add it, just that now we use the Remove() method.



The items are added to the ListBox in the order in which you select them.

If you have any questions comment below or post in the forums.

Stay tunned with Geekpedia.com for more upcoming tutorials .
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this tutorial
Comment Current Comments
by K.R Muthukumaran, on Thursday, May 27th 2004 at 09:59 AM

Respected Sir,
I Want to know more about C#.
The above given notes was very helpful to me.
I want to know how the selected item in the checkedListBox can be displayed in a textBox or a MessageBox.
Please send me the instructions to my E-Mail id.
my E-Mail id is krmuthu14@yahoo.co.in
Thanking you,
Yours sincerely,
K.R Muthukumaran.

by Andrei Pociu on Thursday, May 27th 2004 at 10:44 AM

I emailed you but I'm also posting this here in case someone else needs it.

Add a checkedListBox and a textBox on the form, add a few items to the checkedListBox.
Then doubleclick the checkedListBox to get the default event (checkedListBox1_SelectedIndexChanged).This will take us to the part where we need to code.

The event that occurs every time when you select a different item from the list is called ‘SelectIndexChanged’. Every time this event occurs (you select an item in the list) we want to update the TextBox and display the name of the selected item.

For this we use the following code:

private void checkedListBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
textBox1.Text = checkedListBox1.SelectedItem.ToString();
}

As you can see, in the line:

textBox1.Text = checkedListBox1.SelectedItem.ToString();

…the textbox is updated so that it contains the text of the currently selected item in the checkedListBox.
We also use ToString() because we want the result as string in the textbox.

Add the following line to display the result in a MessageBox:

MessageBox.Show(checkedListBox1.SelectedItem.ToString());


Good luck.

Andrei Pociu.

by melissa on Thursday, May 27th 2004 at 09:48 PM

Hmm..
I've got simliar.. but further problem.
What about if check box list items are connected to the data base, then binded. How can I preselect the check boxes at page load, what ever values in the database?

by Andrei Pociu on Friday, May 28th 2004 at 05:42 AM

You can add a field to the table that will hold a binary value 1 or 0 if the item in the checkedListBox is checked or not checked.
Loop through the rows and set to 'if' conditions. If the value in the row is '1' then:
if(....)
{
checkedListBox1.SetItemChecked(currentItem, 1);
}
else
{
checkedListBox1.SetItemChecked(currentItem, 0);
}

Tell me if you need further help.

by melissa on Tuesday, June 1st 2004 at 06:36 PM

I don't know how to set my if statement condition.
I will have two tables: Person and Interest.
On a person detail's there will be list of interests on a CheckedListBox, then whatever value in the person table-interestID(fk) are cheked on the page load. Another words, what ever the interests of a person in the person table, are checked.

Thank u so much for your help.

by Rajesh on Tuesday, June 8th 2004 at 12:09 AM

I have a list of Clients in the checked list box. All the clients are selected. If i deselect a client from the list box how shall i come to i have the right client data that i have deselected.bcoz i want that data to send to data base for deletion.

by melissa on Tuesday, June 15th 2004 at 08:41 PM

it's me again.. don't get sick of me=p

Do you know how to get the value of CHECKED items' indices (Eg. 1,2,5,...) of a CheckedListBox?

Thanks again=)

by Andrei Pociu on Tuesday, June 15th 2004 at 09:15 PM

You use checkedListBox1.SelectedIndex.

In our example where we have:

if( e.NewValue == CheckState.Checked)
{
selectedList.Items.Add(checkedList.SelectedItem.ToString());
}

if you want to see the index instead of the value use this:

if( e.NewValue == CheckState.Checked)
{
selectedList.Items.Add(checkedList.SelectedIndex.ToString());
}

by Sirrurg on Thursday, June 17th 2004 at 09:24 AM

Hi!

Hopefully u can help me. I want to make a selection through a checkedListBox like shown above, but i have one item in my checkedListBox called "all". If this item is selected i want to unable all other selection/checkboxes as it doesnt make much sense to make more selections.
Is there any "easy" way to do so ? I havent found a property to access this boxes to do so.
Thanks,
sincerely
Sirrurg

by Cezar Tipa on Tuesday, July 6th 2004 at 01:45 AM

The trick with e.NewValue is excellent to use with ListView.ItemChecked which is an "after event" event.

by JIm on Friday, September 24th 2004 at 01:58 AM

The checklistbox demo.
I cant seem to find "itemcheck" property when selected the checklistbox control.
I have also double checked another another's VS .NET.
Please tell me where and how to make checklistbox work when unchecked the item, it will remove the item in the listbox.

by Andrei Pociu on Friday, September 24th 2004 at 07:46 AM

I think I know what you're doing wrong, you're looking at properties instead of events, as there is no ItemCheck property, there is only an event.

So click on the 'thunder' icon in the properties window and there are the events and the ItemCheck event.

Good luck!

by Jim on Friday, September 24th 2004 at 01:05 PM

A THOUSAND THANKS! I got it now.

by jim on Friday, September 24th 2004 at 01:07 PM

BTW, i found your tutorial to be very helpful.
keep up the good works.
MORE C# please or VB.NET

by satya on Friday, November 19th 2004 at 09:34 AM

how can i add items to checked list box in colors.
for e.g. i want to add four items
'Apple', 'Orange', 'Lemon', 'Cake'.
check list box should add 'Apple' item in red color.

thanks in advance

by Andrei Pociu on Friday, November 19th 2004 at 10:25 AM

There's a tutorial covering this:
<a href="http://www.thescarms.com/dotNet/CustomListBox.asp" target="_blank">http://www.thescarms.com/dotNet/CustomListBox.asp</a>

by satya on Tuesday, November 23rd 2004 at 03:58 AM

I worked with ListBox and it has drawmode property.
But checkedListBox control doesnot have DrawMode property. And always this property will be set to Normal.
Hence checkedListBox colors cannot be customised.

However, i decided to work with round-about the solution,
a groupbox with check boxs. If time permits i will make this as a component.

by Sunita on Tuesday, November 30th 2004 at 10:55 AM

Hi,
I would like to know if I have a Valuemember property attched to a checkedlistbox, how can I get the value of the Valuemember when the item is selected.
For eg. the Display might just show "Amazon" but I want to get the Valuemember which might have a value of say '5'. Thanks in advance for your help

by Hicham on Sunday, December 12th 2004 at 11:41 AM

Hi,
I want to retrieve all the items selected in the checkedlistbox.
Actually, when I use this.checklistbox1.SelectedItems.CopyTo(array,index)
it does only copy the last element checked

by vrush on Wednesday, January 5th 2005 at 07:03 AM

Hi,

How to bind CheckedListBox with Dataset?
When i create a CheckedListBox control i dont get its Datasource prperty..
Please help me.

by Syed Irtaza Ali on Monday, February 21st 2005 at 05:45 AM


Hi,

Visit this link for my article on Databinding CheckListBoxControl with DataView

http://blogs.wdevs.com/irtaza/articles/2203.aspx

Using .NET standard CheckedListBoxControl, I couldn't find the properties DataSource, DisplayMember, and ValueMember. Probably the reason would be an older .NET Framework. So instead of getting into the hassle I decided to use the DevExpress CheckedListBoxControl.

Hope this helps out.

by Nick on Tuesday, February 22nd 2005 at 05:31 AM

I am trying to use the Checked list-box control in the C# windows project, but unable to get the datasource, displaymember, valuemember properties. But when I use the Checked list-box control in the windows forms project using VB.NET the above properties appear. Is this a bug with the control or is there a Ghost In My Machine.

Cheers!!!

by saravana on Thursday, April 21st 2005 at 02:35 AM

i 'll need more condition sample coding

by Jon on Friday, April 22nd 2005 at 12:08 PM

How can I get multiple selections within a listbox to appear in a textbox with a comma and a space between each selection?

by Andrei Pociu on Saturday, April 23rd 2005 at 02:51 AM

Here's how (sorry, no code but you can find on Google):

- set the MultiSelect property to true
- iterate through the array of selected items (using a foreach perhaps)
- add the selected values to the textbox plus the comma

So the key is to iterate through all the selected items.

by Jon on Saturday, April 23rd 2005 at 04:14 PM

Still can't get it to work. I'm still new to C# but this is what I have:

for (i=0; i>25; i++)
{
if (genres.Items[i] == genres.SelectedItem)
{
selectgenres[x] = genres.Items[i] + ", ";
x = x + 1;
}
}

genres is my listbox, selectgenres is my string array.
I have 25 items in my listbox, hence the i>25.
I'm not sure how to get the genres.Items[i] to turn into a string.

by Pratyush on Wednesday, April 27th 2005 at 01:20 AM

It is really helpful. Actually I am very new to visit this site. I came to know about it by google. Thanks to This site.

by nickeax on Sunday, May 8th 2005 at 12:15 AM

Thanks for another great tutorial!

by Minh on Wednesday, May 11th 2005 at 11:38 PM

How about the event scroll in checklistBox Control ?

by veronica on Monday, August 1st 2005 at 08:12 PM

I am having trouble creating a upd multi chat with vb.net. I am to chat with one pc but not several at the same time. I want to be able to click on as many IP addresses and send message at the same and recieve aswell. I have attached what I have. Please help

by veronica on Monday, August 1st 2005 at 08:16 PM

attached vb net chat:

Imports System.Windows.Forms
Imports System.Net
Imports System.Net.Sockets
Imports System.Object
Imports System.Threading
Imports System.Text

Public Class Remote_Chat
Inherits System.Windows.Forms.Form
Public threadrecieve As System.Threading.Thread

Public RemoteIpEndPoint As New _
System.Net.IPEndPoint(System.Net.IPAddress.Any, 0)

#Region " Windows Form Designer generated code "
Private udpClient As New System.Net.Sockets.UdpClient
Public receivePoint As IPEndPoint
Private ipadressthreads As Thread()



Public Sub New()
MyBase.New()


InitializeComponent()


udpClient = New UdpClient(5000)
receivePoint = New IPEndPoint(New IPAddress(0), 0)



Dim hostInfo As IPHostEntry = Dns.GetHostByName(Dns.GetHostName())
txtlocalIpAddress.Text = hostInfo.AddressList(0).ToString

Dim ipaddressthreads = New Thread(1) {}

Dim readThread As Thread = New Thread _
(New ThreadStart(AddressOf WaitForPackets))

readThread.Start()


End Sub


Private Sub Remote_Chat_Closing(ByVal sender As System.Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles MyBase.Closing
System.Environment.Exit(System.Environment.ExitCode)


End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub


Private components As System.ComponentModel.IContainer


Friend WithEvents txtInput As System.Windows.Forms.TextBox
Friend WithEvents lstOutput As System.Windows.Forms.ListBox
Friend WithEvents Label1 As System.Windows.Forms.Label
'Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents txtlocalIpAddress As System.Windows.Forms.TextBox
'Friend WithEvents txtRemoteIpAddress As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents TxtScreenName As System.Windows.Forms.TextBox
Friend WithEvents ListBox As System.Windows.Forms.ListBox
Friend WithEvents IPADDRESS As System.Windows.Forms.ListBox
Friend WithEvents CHK1STINPUT As System.Windows.Forms.CheckedListBox
Friend WithEvents cmdclear As System.Windows.Forms.Button
Friend WithEvents cmdexit As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.txtInput = New System.Windows.Forms.TextBox
Me.lstOutput = New System.Windows.Forms.ListBox
Me.txtlocalIpAddress = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.TxtScreenName = New System.Windows.Forms.TextBox
Me.Label3 = New System.Windows.Forms.Label
Me.IPADDRESS = New System.Windows.Forms.ListBox
Me.CHK1STINPUT = New System.Windows.Forms.CheckedListBox
Me.cmdclear = New System.Windows.Forms.Button
Me.cmdexit = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'txtInput
'
Me.txtInput.Location = New System.Drawing.Point(16, 24)
Me.txtInput.Name = "txtInput"
Me.txtInput.Size = New System.Drawing.Size(416, 20)
Me.txtInput.TabIndex = 0
Me.txtInput.Text = ""
'
'lstOutput
'
Me.lstOutput.Location = New System.Drawing.Point(16, 56)
Me.lstOutput.Name = "lstOutput"
Me.lstOutput.Size = New System.Drawing.Size(416, 199)
Me.lstOutput.TabIndex = 1
'
'txtlocalIpAddress
'
Me.txtlocalIpAddress.Enabled = False
Me.txtlocalIpAddress.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.txtlocalIpAddress.Location = New System.Drawing.Point(448, 64)
Me.txtlocalIpAddress.Name = "txtlocalIpAddress"
Me.txtlocalIpAddress.Size = New System.Drawing.Size(248, 26)
Me.txtlocalIpAddress.TabIndex = 2
Me.txtlocalIpAddress.Text = ""
Me.txtlocalIpAddress.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(448, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(144, 40)
Me.Label1.TabIndex = 3
Me.Label1.Text = "Local IP Address"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'TxtScreenName
'
Me.TxtScreenName.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TxtScreenName.Location = New System.Drawing.Point(144, 288)
Me.TxtScreenName.Name = "TxtScreenName"
Me.TxtScreenName.Size = New System.Drawing.Size(288, 26)
Me.TxtScreenName.TabIndex = 6
Me.TxtScreenName.Text = "Anonymous"
'
'Label3
'
Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label3.Location = New System.Drawing.Point(16, 288)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(112, 24)
Me.Label3.TabIndex = 7
Me.Label3.Text = "Screen Name"
'
'IPADDRESS
'
Me.IPADDRESS.Cursor = System.Windows.Forms.Cursors.IBeam
Me.IPADDRESS.Enabled = False
Me.IPADDRESS.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.IPADDRESS.ItemHeight = 16
Me.IPADDRESS.Location = New System.Drawing.Point(592, 184)
Me.IPADDRESS.Name = "IPADDRESS"
Me.IPADDRESS.Size = New System.Drawing.Size(104, 84)
Me.IPADDRESS.TabIndex = 8
'
'CHK1STINPUT
'
Me.CHK1STINPUT.CheckOnClick = True
Me.CHK1STINPUT.Items.AddRange(New Object() {"172.17.237.153", "172.17.237.51", "172.17.237.40", "172.17.237.214", "172.17.237.98"})
Me.CHK1STINPUT.Location = New System.Drawing.Point(448, 184)
Me.CHK1STINPUT.Name = "CHK1STINPUT"
Me.CHK1STINPUT.Size = New System.Drawing.Size(112, 79)
Me.CHK1STINPUT.TabIndex = 9
Me.CHK1STINPUT.ThreeDCheckBoxes = True
'
'cmdclear
'
Me.cmdclear.Location = New System.Drawing.Point(408, 336)
Me.cmdclear.Name = "cmdclear"
Me.cmdclear.Size = New System.Drawing.Size(88, 56)
Me.cmdclear.TabIndex = 10
Me.cmdclear.Text = "CLEAR"
'
'cmdexit
'
Me.cmdexit.Location = New System.Drawing.Point(512, 336)
Me.cmdexit.Name = "cmdexit"
Me.cmdexit.Size = New System.Drawing.Size(75, 56)
Me.cmdexit.TabIndex = 11
Me.cmdexit.Text = "FINISH"
'
'Remote_Chat
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(712, 502)
Me.Controls.Add(Me.cmdexit)
Me.Controls.Add(Me.cmdclear)
Me.Controls.Add(Me.CHK1STINPUT)
Me.Controls.Add(Me.IPADDRESS)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.TxtScreenName)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.txtlocalIpAddress)
Me.Controls.Add(Me.lstOutput)
Me.Controls.Add(Me.txtInput)
Me.Name = "Remote_Chat"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Remote Chat"
Me.ResumeLayout(False)

End Sub

#End Region


'send client text to server
Private Sub txtInput_KeyDown(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles txtInput.KeyDown
' send text to client
If e.KeyCode = Keys.Enter Then
Dim packet As String = TxtScreenName.Text + ": " + txtInput.Text
Dim Data As Byte() = System.Text.Encoding.ASCII.GetBytes(packet)

udpClient.Send(Data, Data.Length, IPADDRESS.Text, 5000)
txtInput.Clear()
End If
End Sub ' txtInput_KeyDown



Public Sub WaitForPackets()
While True

Dim data As Byte() = udpClient.Receive(receivePoint)

Dim tmpString As String = System.Text.Encoding.ASCII.GetString(data)

If (tmpString.Substring(0, 9) = "Anonymous") Then
lstOutput.Items.Insert(0, receivePoint.ToString + ": " + tmpString.Substring(11))

Else
lstOutput.Items.Insert(0, System.Text.Encoding.ASCII.GetString(data))
End If
Beep()

End While

End Sub



Private Sub CHK1STINPUT_itemcheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles CHK1STINPUT.ItemCheck
Dim item As String = CHK1STINPUT.SelectedItem


If e.NewValue = CheckState.Checked Then
IPADDRESS.Items.Add(item)

Else
IPADDRESS.Items.Remove(item)
End If


End Sub

Private Sub cmdclear_CLEAR(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdclear.Click




IPADDRESS.Items.Clear()
CHK1STINPUT.ClearSelected()
CHK1STINPUT.CheckOnClick.Equals(False)




End Sub

Private Sub cmdexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdexit.Click

Application.Exit()

End Sub


End Class

by Manjiri on Friday, November 11th 2005 at 01:54 AM

I would like to know if I have a ValueMember property attched to a checkedlistbox, how can I get the value of the ValueMember for the Product which is stored in Database
For eg. the Display might just show Product as "Cough Cyrup" but I want to get the Valuemember, i.e., ProductCode which might have a value of say '3'. Any help will be appreciated.

by G.Prabhu on Monday, November 28th 2005 at 07:50 AM

Hello sir, How can i insert the combo box selected item into the MsAccess Database (using OleDb Connectivity) using C# Windows Programming.
Please Reply me to my mail id sir!


Thank you.

by Senthil on Tuesday, December 13th 2005 at 03:04 AM

Hello,
How can i copy one row of the GridControl to String array in Vb.net

by Salah on Friday, December 23rd 2005 at 10:36 AM

Hi,
It's a verry good web site.
Thank's
S@l@H

by Poorni on Tuesday, February 7th 2006 at 08:38 AM

How can i insert into database, more than one checkbox using for-loop in c#.net.please help me.

by visha on Thursday, February 23rd 2006 at 04:23 AM

hello sir,
in my checked list box some values are there.that values i retrieved from other form fields. i am having link to that checked list box to that form, if i am going to click the link, its opening the form, if i am going to add the new value it is not adding the same form which is containing the checkedlistbox, it is one more form and adding. how to do,please send me

by anu on Thursday, June 8th 2006 at 01:16 AM

how to display the values in the listbox whatever i selected in one checkedlistbox and after displaying the values in the listbox in that selected values should get remove. how to do

by Alexandre on Monday, June 12th 2006 at 06:01 AM

I woul like to know how can i sort names in a listbox by alphabetic order... In C#.NET

by Ian Williams on Thursday, June 29th 2006 at 04:14 PM

I'm trying to make a checkedlistbox so that the items in the list cannot be checked or unchecked. I have tried setting enabled to false, but this disables the scrollbar. It needs to be scrollable but not able to be checked.

Any ideas on how to do this?

by Akmal on Monday, July 31st 2006 at 03:31 AM

Hi
I'm trying to make same program what u made earlier by using checkedlist box and list box. But I want to add all the checked value in the listbox when i Press Ok button ..

Can u please help me how to do same in C#

by cielo on Thursday, August 3rd 2006 at 02:45 AM

hello. i have problem in using checklistbox. I have an item named "All" located in index 0. i want to selected all items in the chklistbox when i click that item and unchecked all the items if i unchecked it. that part of the code is finished, i used itemcheck event. but my problem is after clicking the item named "All " then user unchecked other item from the chklistbox, the item named "All " should be unchecked. i can't seem to find a logic for it. please help!..

by M.Somon on Sunday, August 6th 2006 at 04:34 PM

But try to bind Checkedlistbox control to the DataSet in VB 2005. Can you?

by RomyJ on Thursday, August 10th 2006 at 06:40 AM

I need to put the selected items in a checklistbox to form a query string ,e.g., sb.append("where month IN " & "(" & "'" & mon & "'" & ")")
If there are many months selected I encountered problem in query syntax mon is the checklistbox selected item.
please help...thank you (please email)

by suresh on Friday, August 11th 2006 at 06:22 AM

Hi,
please i need a solution for this

I have mentioned checkedlistbox1.datasource = ds.tables(0)
CheckedListBox1.DisplayMember = ds.Tables(\"second\").Columns(\"name\").ToString
the table has two rows one column is true or false
and the other column is the name

According to the first column whether its true or false, we need to check the item in the checkedlistbox1 i.e checked if true and un checked if its not true
and the actions taken in the checkedlistbox also should reflect true or false in the table

thanks

by ravi on Friday, September 1st 2006 at 01:00 AM

how can i select all the checkboxes in a checkboxlist from client side in c#.net

by Germanrose on Monday, September 11th 2006 at 11:35 PM

Dear friends,
I have some problems need to help...

I want to add and Object into checkListBox
and then want to show the properties of an Object.

such as:

foreach(DownloadFileObject item in listUpdatedFiles ){
//add item
chklListUpdate.Items.Add(item, true);
//chklListUpdate.Items.Add(item.Url, true);

}
//here I want to show item.Url to screen
//chklListUpdate.Items.ToString();

by Sino on Monday, September 18th 2006 at 12:26 PM

Hi

How can select the newly added item in list box?
I load the list box through \"SELECT\" statement.
And add new row through \"INSERT\" statement.
And then refresh list box using the same \"SELECT\" statement.
I need to select that last added itm(newly added item).

Thanks

Sino

by Daz on Tuesday, September 19th 2006 at 09:26 AM

Hi,

I am having a problem with link lables. I have been trying and trying with no luck. I need to create a link lable everytime the user clicks on the button Create. I can create 1, but this need to be dynamic where the user can create 30 or delete 10 (whatever the case maybe). These links then point to certain files on the Harddrive and are opened in my program. I would like to have the links added to a Listbox or Datagrid. I have searched the Internet for any articles regarding this with no luck what so ever !

Please help

Regards,
Darren

by f on Tuesday, February 13th 2007 at 10:11 PM

er.. in indexchanged and other events, the
(e as sytem.eventargs) is passed..
what information is given in e?
to what sort of object should i cast this and how to extract
data from e?

by alan on Tuesday, February 27th 2007 at 04:19 AM

hi all.
In VB.NET, i want to create a checkedlistbox that contains some items. some of the items is checked based on some condition. if the item is checked, i don't want user to unchecked it, so i need to disable the checked item.
Is this possible with the CheckedListBox control in VB.NET? Thanks.

by Melani Marakkala on Wednesday, April 25th 2007 at 06:23 AM

Sir,
in my C# project,I have added a check box with a button.What it has to do is, when you put a tick on the checkedlistbox item, the selected items shuld display in a text field (In a button click event). and also in the same event (Button click event) i need to deselect all selected values in that checklist box.

ie: actually I need to reload the same checkedListBox as a refreshed one.
How can i do it?

Please answer me soon.
RGDS Mels

by nirmal on Monday, May 21st 2007 at 01:44 AM

i did tried to save the checked items in a checkedlistbox , but if i happen to check more than one item in the checkedlistbox , i'm getting the last item which i checked alone getting saved in the database. How to i create an code to save all the selected items to the database (sql). Then how do i make an button , which once checked , all the check box items should be checked and an another button named Clear checked , which should do the operation of clearing all the checked ones and it should appear as it is unchecked.

Please aid me....

by Amit on Wednesday, May 23rd 2007 at 08:18 AM

i am using checkedlistbox in C# windows app, i wish to disable toggling of check box, i.e. if it is checked user shall not be able to uncheck it on clicking or double clicking and vice versa

by sanjeev on Wednesday, May 30th 2007 at 12:19 AM

Hi
How can i check the check box in java script whether it is cheked or not


Thanku
sanjeev

by mon on Friday, June 15th 2007 at 05:04 AM

on postback, how can you set focus on the selected item in a multi-select listbox? make it on top of the list w/o re-arranging it. thanks in advance!

by mariner on Wednesday, June 20th 2007 at 11:47 AM

How do I write the code for saving a selected item in a listbox to the database?

by Peter on Monday, August 13th 2007 at 04:20 AM

How can I populate checkedListBox with data from a database, such that the listbox displays names, but the program takes valuses of the selected items?
I can't find such option in the designer (as it is in i.e. combobox)?

Is there another solution except doing it manualy?

by poonam on Wednesday, October 17th 2007 at 07:15 AM

i am using checklistbox in my applictaion.if i check one item the other checked item should get unchecked.plz help me
is it possible

by Sairam on Saturday, April 5th 2008 at 01:25 AM

This article is more useful for me sir.Thank u

by mtyu on Saturday, April 26th 2008 at 11:31 AM

i have a checklistbox which can have multiple selections at the same time. then i have a button which when clicked will do something to all of the selected items. is there a way of finding which items got selected? i tried .selectedindices but it only returned the last selected item :/ would be much greatful if someone replied to my ques. thanks!

by Rajani on Tuesday, April 29th 2008 at 03:55 AM

I'm implementing this checkedlistbox control in my project.where i need to select some of the items in this control then that should be displayed in the report viewer. can u help me how to do this?

by sasin on Saturday, May 3rd 2008 at 04:02 AM

hi,

i wanted to know how do u get checkbox selected item ie, if checkboxlist contains 6 items say c1,c2,c3,c4,c5,c6. if i select c4,and c1. i wanted selected index as 4,1 i,e i wanted which is first seelcted index,second selected index and so on. if run loop i can get items selected in checkbox list as 1,4. but iwanted which is selected first,second and so on

Help is aprreciated

by Question.. on Tuesday, May 20th 2008 at 08:46 AM

How can I disable some specific items in checkbox????
It seems that only way to do it by generating a checklistbox and adding it to the listbox.

by aruna on Wednesday, June 11th 2008 at 02:09 AM

Hi this tutorial is very very helpful..


Thankq very much for this.

by aman on Wednesday, June 18th 2008 at 02:44 AM

dear sir,
may i know how to save all the checked items from checklistbox in database using c#.net.plz reply soon

by Ravi Shankar Gautam on Thursday, July 31st 2008 at 11:03 AM

Is it possible to place checkbox to right side in checkedlistbox?

by Kriti on Monday, September 1st 2008 at 11:10 PM

Sir,

I want to know the code for check a listbox items sholud not be same. It can save different value. For example if we make a form for taking all possible size. So in listbox two same size number as 28, 28 can not save in that one listbox. Please reply me soon.

by Divya on Wednesday, September 10th 2008 at 05:12 AM

I've a List box with Multi selection option. I'm storing the selected items to the Database.
But i'm not aware how to retrive those data back to List Box.

Any help towards it is highly appreciated.
Please Help me out......

Regards,
Divya

by SeeSharp on Monday, September 22nd 2008 at 10:14 AM

This may help you in retreiving the values from the database into a checkedlistbox.

Int itemindex;
DataSet ds = new DataSet();
ds = /*** Your function which retrieves the data through SQL Query from the database . this function should return a dataset ***/

foreach (DataTable table in ds.Tables)
{
foreach (DataRow row in table.Rows)
{
ListItem item = new ListItem(row[0].ToString(), row[0].ToString());
this.mycheckedlistbox.Items.Add(item);
itemindex = mycheckedlistbox.Items.IndexOf(item);
mycheckedlistbox.Items[itemindex].Selected = true; /** If you want to make it appear as checked **/
}
}

by Meme on Wednesday, October 22nd 2008 at 11:44 AM

This atricles is trash. All I care about is a quick answer and the author goes on a tantum talking about his momma. Due, learn to write for real developers.

by arjun n on Friday, October 31st 2008 at 06:47 AM

I hav a list view of items with checkboxes..now i had 2 buttons in my form ADD and DELETE .
what i want is when i click the DELETE button watever items that are checked should be deletd from the list.

could anyone help me please.

by T srinivasa reddy on Tuesday, November 4th 2008 at 11:39 PM

GoodMoring sir,
This is Srinivasa reddy, now iam doing project converting vb to vb.net 2005. in vb they are used the listbox, but in .net what i have to use sir and give me which properties i have to use pls give me reply to my mail id its very urgent..........
T.Srinvasa reddy
srinivas_tatikonda@hotmail.com

by Manjunatha on Thursday, November 13th 2008 at 06:53 AM

if anyone want to fetch the checkeditems valuemember from a checkedlistbox they can use the below code...

For i As Integer = 0 To Me.clbProductionLine.CheckedItems.Count - 1

Me.clbProductionLine.CheckedItems.Item(i).row.itemarray(1)

Next

by devi on Tuesday, December 30th 2008 at 02:55 AM

hello sir,
iam using a checkedlistbox and i want to check more than one item so, i suppose to make property selectionmode is multisimple but it says that it is not a valid property. how can i select the items in the checkedlist and how to get the index of the item.can anyone plz help.

by Rich on Saturday, January 24th 2009 at 07:38 PM

In my VB project, I have a multi select checked listbox that is loaded from a file. I am trying to populate a textbox with the items selected from the listbox. Is there also a way to add a select all to the list without adding a command button.

thanks

by saadia on Friday, January 30th 2009 at 04:49 AM

Awesome!!very helpful..

by saadia on Friday, January 30th 2009 at 04:49 AM

Awesome!!very helpful..

by Kiran on Friday, January 30th 2009 at 07:32 AM

Hi
Can i know how to sort the items in Checklist box control? I am getting the items from the Database but not knowing how to display those items in sorted alphabetical order. Plz reply to my kiran225007@gmail.com

Thanks in advance

Regards
Kiran

by Hells on Thursday, March 5th 2009 at 12:58 AM

Hi
You can help me. I want when add items form checklistbox to listbox, I can test 2 items alike if they are alike, it will Error
Thanks in advance

by Hells on Thursday, March 5th 2009 at 01:01 AM

sr I want when add items form textbox to listbox

by Murad on Wednesday, April 15th 2009 at 04:37 AM

Hello Every 1,
i m working in WinCE environment with C#. i have list box and i want to add check boxes in the list box. how can i do this. i have searched over the internet. there is a checked list box suggession but winCE using C# has not such control.

by Mozira on Wednesday, April 15th 2009 at 09:38 AM

Hello Every 1

I have a program that i want to exit when a listbox is empty but if its not asks me if i want to save the changes

by Pam on Thursday, May 14th 2009 at 02:46 AM

Hello!

i want to find the Index Of item in ListBox.
I used IndexOf but it always returns -1???

by Irshad on Monday, May 25th 2009 at 04:24 AM

Wow this is really help me..
God Bless frd...

by as on Monday, July 6th 2009 at 01:02 AM

as

by Adi on Thursday, July 16th 2009 at 05:06 AM

Hello,
I have a checked listbox and for exemple if I select the item nr 2, and I press a submit button, to change me the value for another variable (int test = 0, to became test = 1), if I select another item , to change the value for another variable.
Something like when I press a button, to verify "if (item1 is checked)" then "test = 1".
Thank you :)

by dharmvir on Monday, September 7th 2009 at 01:08 PM

hello,
I want to show the data that is stored in database in respected textbox by binding it with name field in listbox,when i selected one name in listbox then data must be in respected textboxes ..how can solve this problem???
reply me on singh.dharmveer87@gmail.com
Thanks in advnce..

by dharmvir on Monday, September 7th 2009 at 01:08 PM

hello,
I want to show the data that is stored in database in respected textbox by binding it with name field in listbox,when i selected one name in listbox then data must be in respected textboxes ..how can solve this problem???
reply me on singh.dharmveer87@gmail.com
Thanks in advnce..

by leela on Thursday, September 10th 2009 at 04:34 AM

Hi i have one textbox and checked listbox .I have displayed some items in checked list box in page load event.I need to display items which is a match to text which i typed in texbox at run time like google.But i want to display it in a checked list box .I need to do it in asp.net.can any one help me?
I need quick reply.

by leela on Thursday, September 10th 2009 at 04:34 AM

Hi i have one textbox and checked listbox .I have displayed some items in checked list box in page load event.I need to display items which is a match to text which i typed in texbox at run time like google.But i want to display it in a checked list box .I need to do it in asp.net.can any one help me?
I need quick reply.

by Naim Khan on Wednesday, September 16th 2009 at 03:50 AM

Hello sir,
i seen you all solution even i m thanks to you but i have only one problem . i have one checklist box which is binded data from database. i have a ref table on this table i want to store some values from my master table. which is related to this table . sir i want that when i click on chekbox list . chkbox list value should be store in my ref table. and whenever i come to again same form at form load. its show me already selected values in check box.according to my master party id. if i try to deselect then its show me Error. if i select new then its allow me . so plz tell me how can i insert selected values in ChkBox list. i dont have any idea baut it. if u have any code related to this topic then plz give . i really need your help sir. plz help me its too urgent.

thanks in Advance
Naim Khan

by Naim Khan on Wednesday, September 16th 2009 at 03:50 AM

Hello sir,
i seen you all solution even i m thanks to you but i have only one problem . i have one checklist box which is binded data from database. i have a ref table on this table i want to store some values from my master table. which is related to this table . sir i want that when i click on chekbox list . chkbox list value should be store in my ref table. and whenever i come to again same form at form load. its show me already selected values in check box.according to my master party id. if i try to deselect then its show me Error. if i select new then its allow me . so plz tell me how can i insert selected values in ChkBox list. i dont have any idea baut it. if u have any code related to this topic then plz give . i really need your help sir. plz help me its too urgent.

thanks in Advance
Naim Khan

by Linda Rose on Wednesday, September 16th 2009 at 03:41 PM

I have a DropDownList of drivers, which upon selection of a driver, displays a ListBox showing deliveries from a DataSource for that driver. Below that, in a form, we have a CheckBox that "closes" the delivery on completion. We want to remove the listed item from the list. Essentially this works, but the item stays listed until you select a different driver (go out and come back in). An overall page refresh doesn't clear the item. If you have any suggestions, I'd really appreciate some pointers. I'm pretty new to this stuff.

Thanks in advance.
Linda

by silentBreaker on Thursday, September 17th 2009 at 03:14 AM

Hi I am new in using C#. Great code BTW, it works well but I am using web application (.asp) and I want to bind the data from the tables of the database (SQL) and show the result using Listbox. In addition, I want to add the selected item from the checkboxlist to the database... I want to use radiobuttonlist but I know it has the same concept.

Here's my email: jhammapi_c@yahoo.com
Appreciated all the help...

by roshan on Thursday, October 8th 2009 at 04:31 PM

hi this is roshan here i have a doubt that can we move text in textbox from right to left...

by roshan on Thursday, October 8th 2009 at 04:32 PM

hi this is roshan here i have a doubt that can we move text in textbox from right to left...

by roshan on Thursday, October 8th 2009 at 04:33 PM

hi this is roshan here i have a doubt that can we move text in textbox from right to left...
my mail id s ::: roshanxavio@gmail.com........helb me blll

by roshan on Thursday, October 8th 2009 at 04:35 PM

hi this is roshan here i have a doubt i hav two forms i need to user to enter this name in textbox and after he move to next bage i should disblay his name in label...after second form loaded,,,, send me to roshanxavio@gmail.com

by roshan on Thursday, October 8th 2009 at 04:35 PM

hi this is roshan here i have a doubt i hav two forms i need to user to enter this name in textbox and after he move to next bage i should disblay his name in label...after second form loaded,,,, send me to roshanxavio@gmail.com

by roshan on Thursday, October 8th 2009 at 04:36 PM

hi this is roshan here i have a doubt i hav two forms i need to user to enter this name in textbox and after he move to next bage i should disblay his name in label...after second form loaded,,,, send me to roshanxavio@gmail.com

by roshan on Thursday, October 8th 2009 at 04:36 PM

hi this is roshan here i have a doubt i hav two forms i need to user to enter this name in textbox and after he move to next bage i should disblay his name in label...after second form loaded,,,, send me to roshanxavio@gmail.com

by Kumar on Saturday, October 24th 2009 at 03:38 PM

Hi,

I am trying to check the status of checkedlistbox (ie if item 2 selected in checkedlistbox then I want to multiply some int value with the textbox value and print in a seperate textbox)

if (checkedlistbox selected ( eg second item 2 (Debit card)))

{
Textbox1.value=20;
Textbox2=(Textbox1.value)*(0.50)
print(Textbox2.value)
}


I request you to give the answer in C sharp. I appreciate your work.....

by shalu on Friday, November 6th 2009 at 04:36 AM

Hello Everyone
'************************************************
select * from ItemTable where itemname is the item which is checked in checkedlistbox..
'************************************************
<b> how can i write query for this...thanx in advance

by shalu on Friday, November 6th 2009 at 04:37 AM

Hello Everyone
'************************************************
select * from ItemTable where itemname is the item which is checked in checkedlistbox..
'************************************************
<b> how can i write query for this (IN VB.NET)...thanx in advance

by shalu on Friday, November 6th 2009 at 04:37 AM

Hello Everyone
'************************************************
select * from ItemTable where itemname is the item which is checked in checkedlistbox..
'************************************************
<b> how can i write query for this (IN VB.NET)...thanx in advance

by Shalu jain on Friday, November 6th 2009 at 04:53 AM

Hello Everyone
'************************************************
select * from ItemTable where itemname is the item which is checked in checkedlistbox..
'************************************************
how can i write query for this (IN VB.NET)...thanx in advance
Email Id: shalu21jain@yahoo.com
pls rep on ma ID

by kiran on Sunday, December 20th 2009 at 11:42 PM

hi .i hav one doupt i hope u wil solve that .

i hav cbxlist in that i want to enable the selected items .
plz help me

by kiran on Sunday, December 20th 2009 at 11:43 PM

hi .i hav one doupt i hope u wil solve that .

i hav cbxlist in that i want to enable the selected items .
plz help me

by Shrawan Kumar on Saturday, January 16th 2010 at 06:05 AM

Respected Sir,
The above given details was very helpful to me. I want to know more about c#.
I want to know how the selected items in the checkedlistbox can be inserted into a database table.
Please send me the syntax to my e-mail ID given below:
skmanash@gmail.com
Thanking you,
Your's sincerely
Shrawan Kumar

by supriya on Monday, January 18th 2010 at 01:20 AM

I am using ListCheckbox and While the focus is inside one of the items of listcheckbox and Enter key is pressed the focus should move to the next Item in the listcheckbox and that item should be checked.
Please help me out by sending the code.

by supriya on Monday, January 18th 2010 at 01:20 AM

I am using ListCheckbox and While the focus is inside one of the items of listcheckbox and Enter key is pressed the focus should move to the next Item in the listcheckbox and that item should be checked.
Please help me out by sending the code.

by Hakkı Cepkin on Friday, February 19th 2010 at 04:17 AM

thanks good information

by Hakkı Cepkin on Friday, February 19th 2010 at 04:17 AM

thanks good information

by Hakkı Cepkin on Friday, February 19th 2010 at 04:17 AM

thanks good information

by Hakkı Cepkin on Friday, February 19th 2010 at 04:17 AM

thanks good information

by Hakkı Cepkin on Friday, February 19th 2010 at 04:17 AM

thanks good information

by Chris on Tuesday, March 16th 2010 at 05:44 PM

I am generating a string by combining the values from 5 text boxes items in a CheckedListBox (chkTLD). I want to write the strings I create to a ListBox(itemList).

I am able to generate the string when 1 item in the CheckedListBox (chkTLD) is checked. However, when I check multiple items in chkTLD, only the last item selected is displayed in itemList. I want all iterations to display at once in the ListBox(itemList).

I have an event called generate() that is envoked by hitting the Create button on my form. I don't know how to create multiple strings from having multiple tld items selected. Can you help?

Code is below:


protected const string TEMPLATE = "{0}-{1}-{2}-v{3}-{4}{5}";
private void generate()
{

string testName = txtName1.Text.Trim();
string testType = txtName2.Text.Trim();
string testNumber = txtTestNumber.Text.Trim();
string versionNumber = txtIteration.Text.Trim();
string tld = chkTLD.Text.Trim();
string dateString = DateTime.Now.ToString("yyyyMMdd");
object[] parameters = {
testName,
testType,
testNumber,
versionNumber,
dateString,
tld
};
string domainName = string.Format(TEMPLATE, parameters);



if (chkTLD.SelectedItems == null)
{
MessageBox.Show("Error", "TLD is required", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
itemList.Items.Add(domainName);
}
}





private void btnCreate_Click(object sender, EventArgs e)
{
this.generate();

}

by re on Friday, March 19th 2010 at 11:52 AM

private void chkLB1_ItemCheck(object sender, ItemCheckEventArgs e)
{

if (e.NewValue == CheckState.Checked)
{
MessageBox.Show(chkLB1.SelectedItem.ToString() " ON");
}

else
{
MessageBox.Show(chkLB1.SelectedItem.ToString() " OFF");
}

}

by Chris on Friday, March 19th 2010 at 01:34 PM

thanks for the info, but that just displays to a msg box of only the CheckedListBox value.

I want my generate() method to write all the strings that are created from my CheckedListBox selections to my ListBox. As written, it just writes last item checked, not ALL items checked.

by pete on Friday, March 19th 2010 at 02:19 PM


int car = txt1.Text.Length -1;
int caract2 = txt2.Text.Length;
string word ="";
int cont=0;


for (int i = 0 ; i <=car-caract2 1 ; i )
{
word = txt1.Text.Substring(i, caract2);

if (word == txt2.Text)
{
cont= cont 1;

}
}
MessageBox.Show("there are " cont " " txt2.Text );

by mohit on Sunday, April 4th 2010 at 01:36 PM

my question if i show all the columns in the listbox corresponding with checkbox and i want only that column should be bind at runtime which checbbox is selected true then how can i achieve in wpf. Can anyone help me.

Thanks in advance

by mohit on Sunday, April 4th 2010 at 01:36 PM

my question if i show all the columns in the listbox corresponding with checkbox and i want only that column should be bind at runtime which checbbox is selected true then how can i achieve in wpf. Can anyone help me.

Thanks in advance

by mohit on Sunday, April 4th 2010 at 01:36 PM

my question if i show all the columns in the listbox corresponding with checkbox and i want only that column should be bind at runtime which checbbox is selected true then how can i achieve in wpf. Can anyone help me.

Thanks in advance

by heritage on Saturday, April 10th 2010 at 02:42 AM

I want to insert value<yes/no> of check box into the table(database)using C#.can you help me.Please send the code.

by jia on Wednesday, April 21st 2010 at 03:33 AM

I'm implementing a checkedlistbox control in my project.where i need to select some of the items in chklistbox, then that items should be displayed in the report viewer. can anyone help me how to do this?
Plz send me related code at this Email address jiatb439@gmail.com

by Osman on Thursday, April 22nd 2010 at 03:40 AM

So, how is multi column inserting?

by umesh on Sunday, May 2nd 2010 at 10:47 AM

i want to get your help
i have to make a checkedListBox in one form by click event of button of any other form
as to make query in sql 2005 we select some tables and as we select table_name a checked list box is created and the correspond table and their field name is automatically becomes in checked list box

by Max on Monday, May 3rd 2010 at 01:24 PM

im trying to remove an item from a listbox by double clicking on it.with out use of a button

by Max on Monday, May 3rd 2010 at 01:24 PM

im trying to remove an item from a listbox by double clicking on it.with out use of a button

by Mrigendra Singh on Friday, May 14th 2010 at 09:24 AM

Today i found that for multiple selection, List Builder is also used. I would like to get the details of it...

by siyaram on Thursday, May 20th 2010 at 03:55 AM

I want to CheckedListBox selected rows insert into database,


(2) Datagridview selected row item insert database.

by siyaram on Thursday, May 20th 2010 at 03:55 AM

I want to CheckedListBox selected rows insert into database,


(2) Datagridview selected row item insert database.

by siyaram on Thursday, May 20th 2010 at 03:55 AM

I want to CheckedListBox selected rows insert into database,


(2) Datagridview selected row item insert database.

by siyaram on Thursday, May 20th 2010 at 03:55 AM

I want to CheckedListBox selected rows insert into database,


(2) Datagridview selected row item insert database.

by siyaram on Thursday, May 20th 2010 at 03:56 AM

I want to CheckedListBox selected rows insert into database


(2) Datagridview selected row item insert database.(coding)

by megha on Thursday, June 24th 2010 at 03:48 AM

dear sir i want 2 knw ths ....i hv made a method named display() and in it i want to display both number and name...wt should i write in listbox event so that we cn select both number and name.

by megha on Thursday, June 24th 2010 at 03:48 AM

dear sir i want 2 knw ths ....i hv made a method named display() and in it i want to display both number and name...wt should i write in listbox event so that we cn select both number and name.

by Max on Thursday, June 24th 2010 at 12:26 PM

dear sir im trying to update a database using a primary key that was autogenerated,of which i dont know it

by Max on Thursday, June 24th 2010 at 12:27 PM

dear sir im trying to update a database using a primary key that was autogenerated,of which i dont know it

by LeeC on Thursday, June 24th 2010 at 02:34 PM

@megha:
The way I read your question, I'm able to interpret it a number of different ways. Regardless, you're asking if there is a way for a list to contain two objects within each item. What I'm not able to discern is whether you:
A) want to display both objects in the list (ie as two independent columns that mimic or share actions (ie scrolling, selecting, etc. )
B) want to display only one of the objects, but still be associated with the other object
C) want to concatenate the two objects into a simple string object to be displayed by the listbox.
D) want to concatenate the two objects into a string, but retain the original objects to be accessed by functions acting on the list without parsing the string and searching for the members individually.

Those theories are how you will go about your solution, as I don't want to delve into it anymore than I have to without knowing exactly what it is you're attempting.


by Nitin on Saturday, June 26th 2010 at 01:44 AM

Thank you

i had a problem with checkedboxlist but right now i don't have any problem with checkboxlist.

by Bhagwan Rashnish on Saturday, June 26th 2010 at 09:15 AM

I am trying to use checklistbox but nothing is working out. I am from India, so I came to here from Google.

by basha on Monday, July 5th 2010 at 02:52 AM

hi
dki
d

d

by basha on Monday, July 5th 2010 at 02:53 AM

hi
dki
d

d


Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Tutorials
There are no related tutorials.

Comment Related Source Code
There is no related source code.

Jobs C# Job Search
My skills include:
Enter a City:

Select a State:


Advanced Search >>
Sponsors
Discover Geekpedia

Other Resources