I have a Page containing a DataGrid. I need to populate this from 2 separate sources. The 1st three columns of data I read from a text file (both the column headers, and the subsequent rows of data).
After that there is anywhere from 1 to 100 columns I need to add that will just contain checkboxes.
I'm creating the 1st 3 columns as type DataGridTextColumn, and the remaining columns I am creating as type DataGridCheckBoxColumn.
I *think* I'm doing this all correctly, except for three problems.
1. I can't SEE the data in the 1st 3 columns.
2. When I try to click on the Checkboxes in the remaining columns they don't Check / Uncheck
3. If I double-click the checkboxes I get an error - "EditItem is not allowed for this view.
Below is the code that creates this grid. When I created a Winforms version of this dialog, I trapped the CurrentCellDirtyStateChanged to commit the Checked/Unchecked state, and CellValueChanged to operate on the resulting change. That's part of my Checkboxes problem - I haven't found a WPF equivalent.
Any suggestions on how to solve my problems?
private void CreateMapSamplesToAssaysTable( )
{
try
{
this.dgViewSamples.Items.Clear();
this.dgViewSamples.Columns.Clear( );
List<string> strColHeaders = new List<string>( );
strColHeaders.Add( rm.GetString( "SampleIDColumnTitle" ) );
strColHeaders.Add( rm.GetString( "SampleDescriptionColumnTitle" ) );
strColHeaders.Add( rm.GetString( "DilutionFactorColumnTitle" ) );
int numAssays = data.SelectedAssays.Count;
for( int nIdx = 0; nIdx < numAssays; nIdx++ )
{
string selectedAssayName = data.SelectedAssays[ nIdx ];
strColHeaders.Add( selectedAssayName );
}
int nCols = strColHeaders.Count( );
for( int nIdx = 0; nIdx < nCols; nIdx++ )
{
DataGridColumn col = null;
switch( nIdx )
{
case 0:
case 1:
case 2:
col = new DataGridTextColumn( );
col.IsReadOnly = true;
break;
default:
col = new DataGridCheckBoxColumn( );
col.IsReadOnly = false;
break;
}
col.Header = strColHeaders[ nIdx ];
this.dgViewSamples.Columns.Add( col );
}
string strFileName = data.WorklistPath;
StreamReader reader = new StreamReader( strFileName );
string strLine = null;
strLine = reader.ReadLine( );
while( ( strLine = reader.ReadLine( ) ) != null )
{
char[ ] chDelimiter = new char[ ] { '\t' };
string[ ] strParts = strLine.Split( chDelimiter,
StringSplitOptions.None );
if( strParts.Length >= 3 )
{
string[] strRow = {strParts[0], strParts[1], strParts[2]};
this.dgViewSamples.Items.Add( strRow );
}
}
reader.Close( );
}
catch( Exception ex )
{
StackFrame sf = new StackFrame( );
Errors.ErrorMessage( ex, sf, true );
}
}</string></string>