1
Answer

FreeForm on DataGrid project

Andrzej Wegierski

Andrzej Wegierski

21y
1.5k
1
I create a FreeForm object from DataGrid. It use a UserControl object with TextBoxes etc. multiplied by DataGrid screen rows and added to Controls[] and custom DataGridColumnStyles to link UserControls to DataGrid. My informations are wery short - but the project is quite big, sorry. I don't use data binding because of it doesn't work in all cases. So I use: protected override void Paint(Graphics gr,Rectangle rc,CurrencyManager cm,int row,Brush bb,Brush fb,bool rtl) method to set values in TextBoxes on UserControls. property Text and TextChanged event to save changes in DataGrid.DataSource (DataView) View: public void SaveCell(int row,object val) { DataView dv=((FreeDataGrid)this.DataGridTableStyle.DataGrid).View; try { // null test if(val==null || val.ToString().Trim()=="" || NullText.Equals(val)) val=DBNull.Value; // saving dv[row][this.MappingName]=val; dv[row].EndEdit(); } catch {} } It doesn't work in one case, too: when I try to add new row with primary case similar to existing one (first keys identical, one - the last - different) EndEdit method generates exception, so during the next Paint() these fields are cleared. Saving to DataView and EndEdit it's generally an error I think. But what I can do in this matter? May be use another events or methods or save to DataGrid cells? May be someone can help me ... Thx in adv

Answers (1)