No header row in datagrid bind to list

Feb 25, 2014 at 9:12 AM
Hi everybody! I have a trouble.

I have a class
private class EventJournalRecord
        {
            public DateTime Date { get; set; }
            public String EventType { get; set; }
            public String Message { get; set; }
            public Color BackgroundColor { get; set; }
            public EventJournalDTO EventJournalRec { get; set; }
        }
then i get list of objects of this class and bind it to datagrid (i need datagrid because list contains 10k+ rows) like this:
I initialize all the stuff:
private void InitDataGridView()
        {
            eventJournalDataGrid.Selection.SelectionChanged += eventJournalDataGridView_SelectionChanged;
            eventJournalDataGrid.AutoStretchColumnsToFitWidth = true;
            eventJournalDataGrid.Rows.AutoSizeMode = SourceGrid.AutoSizeMode.EnableStretch;

            eventJournalDataGrid.FixedRows = 1;
            eventJournalDataGrid.FixedColumns = 1;

            eventJournalDataGrid.Columns.Insert(0, SourceGrid.DataGridColumn.CreateRowHeader(eventJournalDataGrid));            
            
            InitEventJournalColumns();
            eventJournalDataGrid.Columns.AutoSizeView();
        }
private void InitEventJournalColumns()
        {
            eventJournalDataGrid.Columns.Clear();

            var viewString = new SourceGrid.Cells.Views.Cell();
            viewString.BackColor = Color.White;            
            viewString.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft;
            viewString.WordWrap = true;
  
            var dateColumn = eventJournalDataGrid.Columns.Add("Date","Date",
                typeof(DateTime));
            dateColumn.DataCell.View = viewString;

            if (!IsRealTimeJournal)
            {
                var typeColumn = eventJournalDataGrid.Columns.Add("EventType", SettingsHelper.LocRM.GetString("EventTypeTitle"),
                    typeof (string));
                typeColumn.DataCell.View = viewString;
            }

            var messageColumn = eventJournalDataGrid.Columns.Add("Message",
                "Message", typeof (string));
            messageColumn.DataCell.View = viewString;
        }
then somewhere i call this method:
private void BindSource(List<EventJournalDTO> eventJournalRecords)
        {
            lock (_eventJournalSync)
            {
            _eventJournalRecords = eventJournalRecords == null || eventJournalRecords.Count == 0
                ? new BindingList<EventJournalRecord>()
                : new BindingList<EventJournalRecord>(GetEventJournalViewRecords(eventJournalRecords));

            if(IsRealTimeJournal)
                FilterJournal();

                var boundList =
                    new DevAge.ComponentModel.BoundList<EventJournalRecord>(
                        _eventJournalRecords);
                eventJournalDataGrid.DataSource = boundList;
                if (eventJournalRecords != null && eventJournalRecords.Any())
                {
                    LastEventTime = eventJournalRecords.Max(rec => rec.EventTime);
                }
            }
So i have a trouble : header row is not shown, i cannot resize columns and i don't know what am i doing wrong.
Feb 25, 2014 at 12:21 PM
Sorry, the trouble was that i called eventJournalDataGrid.Columns.Clear();