Click here to Skip to main content
15,917,005 members
Home / Discussions / C#
   

C#

 
GeneralDatakeyfield in Datagrid Pin
livez12-Jul-05 4:07
livez12-Jul-05 4:07 
hello

I have a datagrid which consists of two columns, one templatecolumn and one boundcolumn. the templatecolumn's got two checkboxes, one in the header (when pressed it checks all checkboxes) and one for every row.
the boundcolumn shows data from a datatable. when I press a button I want to check which of the checkboxes are checked, and for everone that is, get the datakey for that row and put it in an array.

to accomplish this I do

<br />
CheckBox cb;<br />
int i = 0;<br />
foreach( DataGridItem dgi in this.MyDataGrid.Items ) <br />
{<br />
	cb = (CheckBox) dgi.Cells[0].Controls[1];<br />
	//If it's selected then add it to ArrayList<br />
	if ( cb != null && cb.Checked )  <br />
	   {<br />
             id = (int) MyDataGrid.DataKeys[i];<br />
             alSelectedValues.Add(id.ToString());<br />
	   } <br />
	i++;<br />
}<br />


but when I run program I get "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index "

can anyone see whats wrong?

/Regards Magnus
GeneralPessimistic locking Pin
rmedo12-Jul-05 3:47
rmedo12-Jul-05 3:47 
GeneralRe: Pessimistic locking Pin
Dave Kreskowiak12-Jul-05 5:56
mveDave Kreskowiak12-Jul-05 5:56 
GeneralWi-fi Pin
jonty1912-Jul-05 3:34
jonty1912-Jul-05 3:34 
GeneralRe: Wi-fi Pin
Dave Kreskowiak12-Jul-05 5:55
mveDave Kreskowiak12-Jul-05 5:55 
GeneralRe: Wi-fi Pin
jonty1912-Jul-05 6:06
jonty1912-Jul-05 6:06 
GeneralCrystal Reports help required Pin
asmyan12-Jul-05 3:27
asmyan12-Jul-05 3:27 
GeneralWindows Service Pin
the_jebus12-Jul-05 3:18
the_jebus12-Jul-05 3:18 
GeneralRe: Windows Service Pin
Dave Kreskowiak12-Jul-05 5:52
mveDave Kreskowiak12-Jul-05 5:52 
GeneralRe: Windows Service Pin
the_jebus12-Jul-05 7:26
the_jebus12-Jul-05 7:26 
GeneralRe: Windows Service Pin
Dave Kreskowiak12-Jul-05 8:10
mveDave Kreskowiak12-Jul-05 8:10 
QuestionHow to save image of a panel with panels inside it Pin
Atlemann12-Jul-05 3:01
Atlemann12-Jul-05 3:01 
GeneralSening Keys to App using directinput Pin
moongood12-Jul-05 2:55
moongood12-Jul-05 2:55 
GeneralRe: Sening Keys to App using directinput Pin
Dave Kreskowiak12-Jul-05 5:23
mveDave Kreskowiak12-Jul-05 5:23 
GeneralC++, C#, 'main' conflict and confusion Pin
outofstock12-Jul-05 2:42
outofstock12-Jul-05 2:42 
GeneralRe: C++, C#, 'main' conflict and confusion Pin
S. Senthil Kumar12-Jul-05 4:33
S. Senthil Kumar12-Jul-05 4:33 
GeneralDatabase access Pin
parrot12312-Jul-05 2:06
parrot12312-Jul-05 2:06 
GeneralRe: Database access Pin
Alomgir Miah12-Jul-05 4:23
Alomgir Miah12-Jul-05 4:23 
GeneralRe: Database access Pin
V.12-Jul-05 5:16
professionalV.12-Jul-05 5:16 
GeneralRe: Database access Pin
parrot12312-Jul-05 7:30
parrot12312-Jul-05 7:30 
GeneralInheritance problem Pin
tttyip12-Jul-05 2:01
tttyip12-Jul-05 2:01 
GeneralRe: Inheritance problem Pin
Member 91369412-Jul-05 3:04
Member 91369412-Jul-05 3:04 
GeneralRe: Inheritance problem Pin
S. Senthil Kumar12-Jul-05 4:32
S. Senthil Kumar12-Jul-05 4:32 
GeneralPicture problem Pin
Anonymous12-Jul-05 1:50
Anonymous12-Jul-05 1:50 
GeneralRe: Picture problem Pin
Lalit N Dubey12-Jul-05 2:13
Lalit N Dubey12-Jul-05 2:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.