473,387 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

[c#-windows form] multi column list box...?

77
i need something simmilar to a multi column listbox. i need to get certain values back form what the user selects. ofr instance if the text of the items in the list say
smith john 99999 96f
i would need to get the 99999 part. i could simply replace the space and put them into a array however, some people in the data im using have spaces in surnames so you then end up with and extra space. example:
al capone john 99999 96f

where 99999 used to be array[2] it is now array[3]
i could of course include a for loop to detect for integers but this would make for extremly messy code and if someting goes worng it could cause a lot of errors.

so i need something like this for instance
Expand|Select|Wrap|Line Numbers
  1. |        TEXT            |    Value    |
  2. smith john 99999 96f     |    99999    |
  3. al capone john 99991 93g |    99991    |
  4.  

so the user will not see the value of the iutem but will see the text.

it's similar to the way the value attribute works in html..


any ideas?

All help is greatly apprieceated :o)
Piercy
Aug 13 '07 #1
12 4629
Plater
7,872 Expert 4TB
Use a DataSource.
You can create a DataTable with all your information and then set it as the datasource for the listbox.
Set the DisplayMember ="Username" (or whatever you called the column you want them to see)
Set the ValueMember ="ID" (or whatever you called the column with your integer number)
Aug 13 '07 #2
piercy
77
thats sounds like exactly what im looking for however.. the datatable i already have in place (which does already contain the info) doesnt seem to show up in my listbox datasource properties box. ... could be something to do with visual studio 2003... but im going to look into it. if you got any ideas let me know.

Many thanks,
Piercy
Aug 13 '07 #3
Plater
7,872 Expert 4TB
You will have to do the leg work yourself in creating the datasource from the database (I think)
I've never used the UI DataSource thinger so I don't know what you can and cannot do with it
Aug 13 '07 #4
piercy
77
You will have to do the leg work yourself in creating the datasource from the database (I think)
I've never used the UI DataSource thinger so I don't know what you can and cannot do with it
erm.. ive got the datatable from the database its jsut setting the data table as the data source... if im making sense. the datatable already populates itself on the call of a function and was currently populating the listbox in a different way.

looking through lots of help docs to see if can find the answer..

thanks
Piercy
Aug 13 '07 #5
TRScheel
638 Expert 512MB
i need something simmilar to a multi column listbox. i need to get certain values back form what the user selects. ofr instance if the text of the items in the list say
smith john 99999 96f
i would need to get the 99999 part. i could simply replace the space and put them into a array however, some people in the data im using have spaces in surnames so you then end up with and extra space. example:
al capone john 99999 96f

where 99999 used to be array[2] it is now array[3]
i could of course include a for loop to detect for integers but this would make for extremly messy code and if someting goes worng it could cause a lot of errors.

so i need something like this for instance
Expand|Select|Wrap|Line Numbers
  1. |        TEXT            |    Value    |
  2. smith john 99999 96f     |    99999    |
  3. al capone john 99991 93g |    99991    |
  4.  

so the user will not see the value of the iutem but will see the text.

it's similar to the way the value attribute works in html..


any ideas?

All help is greatly apprieceated :o)
Piercy
Depending on the number of rows, this can be time consuming... but... it should work:

Expand|Select|Wrap|Line Numbers
  1. string values[] = YourRow.Split(' ');
  2. for(int i = 0; i < values.length; i++)
  3. {
  4.     int temp = 0;
  5.     bool attempt = false;
  6.  
  7.     attempt = int.TryParse(values[i], temp);
  8.     if(attempt && temp.ToString() == values[i])
  9.     {
  10.          // You have a space sepearted item that is all numbers
  11.     }
  12. }
  13.  
Aug 13 '07 #6
piercy
77
Depending on the number of rows, this can be time consuming... but... it should work:

Expand|Select|Wrap|Line Numbers
  1. string values[] = YourRow.Split(' ');
  2. for(int i = 0; i < values.length; i++)
  3. {
  4.     int temp = 0;
  5.     bool attempt = false;
  6.  
  7.     attempt = int.TryParse(values[i], temp);
  8.     if(attempt && temp.ToString() == values[i])
  9.     {
  10.          // You have a space sepearted item that is all numbers
  11.     }
  12. }
  13.  
doesnt this just do the same as i was doing as in searching for the int in the string via a loop??... i may be wrong as im new to c#..


Thanks again
Piercy
Aug 13 '07 #7
Plater
7,872 Expert 4TB
If you have a datatable called say "mydt" and a listbox called say "mylb".
AND assume in your datatable you have columns "USERNAME" and "ID".

Then you would do say:
Expand|Select|Wrap|Line Numbers
  1. mylb.DataSource=mydt;
  2. mylb.DisplayMember="USERNAME";
  3. mylb.ValueMember="ID";
  4.  
And that should be all you need.
Aug 13 '07 #8
TRScheel
638 Expert 512MB
doesnt this just do the same as i was doing as in searching for the int in the string via a loop??... i may be wrong as im new to c#..


Thanks again
Piercy
Ya but otherwise you need to have a seperator be it a symbol for the integer portion to follow or split them into seperate columns to begin with. You cant just magically have the first integer in the group.
Aug 13 '07 #9
piercy
77
If you have a datatable called say "mydt" and a listbox called say "mylb".
AND assume in your datatable you have columns "USERNAME" and "ID".

Then you would do say:

Code: ( text )
mylb.DataSource=mydt;
mylb.DisplayMember="USERNAME";
mylb.ValueMember="ID";


And that should be all you need.



wow.. that helped a lot.. my listbox has been populated with data :D (and faster than it did before... however, is there a way to display two or more columns in the lbData.DisplayMember property. if need be i will merge the columns earlier on so the data table already has them merged but if its possible it would be good to be able to have the columns SurName and ForeName displayed.


can this be done or do i have to merge the datatable columns early on?


Many thanks your answers are greatly appreciated.
Piercy
Aug 13 '07 #10
piercy
77
actually it was easy enough just to create another column with the values i wanted.. so now i have a display column just for display and i can browse the rest of it from the data table if i want.

Thanks very much!!
you all been a great help.
Piercy
Aug 13 '07 #11
Plater
7,872 Expert 4TB
I am fairly certain there is a way to make multiple columns show up, only I don't know how.
If you merge the columns in your datatable you can use them just fine though.
Aug 13 '07 #12
piercy
77
.. yeah see the only problem with how things have planned out is that i did a load of stuff then it was a sorta joint decision that how i had done it wasnt good. so everything i written has gone to pot near enough and i have to redo the majority of the app.. starting with the drag and drop function which now dont work... this gunna be a bit of a bitch any ideas?
Aug 13 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Andy Mabbett | last post by:
I have a page with a list, presented, by use of CSS, sequentially, in this order: 1 2 3 4 5 6 7 8 9 10 11 12 in smaller windows, it reflows thus:
4
by: MSD | last post by:
I am running a report that uses a query as its record source and opens a form collecting beginning and ending item numbers to feed to the query. This works, but now I'm trying to use the result of...
3
by: syounger | last post by:
Hi. I have a report in Access 2000 that is based on selection made from a series of interdependent list boxes. The boxes I have right now are Source, Table, Column, Date. The user chooses Source...
6
by: CindyH | last post by:
Hi Does anyone know how to create a multi column combo box from the same table? Thanks, Cindy
2
by: Zlatko Matić | last post by:
Hello. How to reference selected values from a multi-select list box, as a criteria in a query ? Is it possible at all? Regards, Zlatko
1
by: cmay | last post by:
I need to databind a record set from the database into a page. The output I need is a textbox and a label for every item in the resultset, but I don't want a long vertical list... instead I want...
3
by: Nathan Sokalski | last post by:
I am looking to create a multi-column list that is scrollable, kind of like a ListBox control, only I need a way to align the columns of text that I will have (I would use spaces, but because the...
1
by: KrazyKasper | last post by:
Access 2003 – Multi-Column List Box – Select Multiple Items I have a multi-column (3 columns) list box that works well to select one set of records or all sets of records (based on the first field...
2
by: KrazyKasper | last post by:
I have a Multi-Column List Box named List10 that is populated via a query (qry_OptimizeIt3). I’m looking to create three Buttons, one above each column that will re-sort the list in ascending order...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.