c# - WPF: Getting row header of selected cells -


so have filled datagrid values. have selected cells , need column , row header of each cell.

i have found out how column header easily, row 1 doesn't want come me easy...

my code of getting values:

string[,] matrix = new string[2, 4];  

^ have maximum of 4 selected cells - want keep value of headers(row + column) strings.

ilist<datagridcellinfo> thechosenones = mydatagrid.selectedcells;  int c = 0;  foreach (datagridcellinfo cell in thechosenones)     {        matrix[1,c] = cell.column.header.tostring(); 

^ gives me want - string column header of cell contains

       matrix[0,c] = cell.item.tostring(); 

^ gives me - "system.data.datarowview"

       c++;     } 

also should add information i'm using selectionmode="extended" + selectionunit="cell" + datagrid has both row , column headers - need values.

i looking @ documentation: http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.selectedcells.aspx , here: http://msdn.microsoft.com/en-us/library/system.windows.controls.datagridcellinfo.aspx says can row there visual studio ain't letting me (tried like: matrix[0,c] = cell.row.header.tostring(); )

also checked http://msdn.microsoft.com/en-us/library/system.data.datarowview.aspx .. , tried working properties, won't work.

what doing wrong? help.

edit: "upgraded" code found here still doesn't give me want :|

matrix[0, c] = ((datarowview)cell.item).row.tostring(); 

^ can row(as "system.data.datarow").. why can't row header?

it might weird found answer on own.. :d (as long noone else wanted me :'( ..)

it might long/weird/notbest solution, it's working want it. if u guys have better solution tell me :]

found link: http://techiethings.blogspot.in/2010/05/get-wpf-datagrid-row-and-cell.html

so decided row index:

instead:

matrix[0,c] = cell.item.tostring(); 

i used this:

myarray[] = {my row header values};

matrix[0,c] = myarray[((datagridrow)mydatagrid.itemcontainergenerator.containerfromitem(cell.item)).getindex()] ; 

it works need i'm satisfied. if u see wrong or better solution, add answer/comments please.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -