ComboBox in DataGrid
-
Hi, I want ComboBoxes displayed in all columns of datgrid, always visible. And there are a lot of things in DataGrid that are difficult to resolve. For ex, I always see one extra row at the bottom even when I have added the rows through DataTable and the DataTable.Row.Count is correct but Grid.VisibleRowCount is 1 greater. Also, I don't want the column with readonly=true to be selected, whereas when I click on that column the background of that row becomes gray ! Any help would be highly appreciated :((! Thanks.
-
Hi, I want ComboBoxes displayed in all columns of datgrid, always visible. And there are a lot of things in DataGrid that are difficult to resolve. For ex, I always see one extra row at the bottom even when I have added the rows through DataTable and the DataTable.Row.Count is correct but Grid.VisibleRowCount is 1 greater. Also, I don't want the column with readonly=true to be selected, whereas when I click on that column the background of that row becomes gray ! Any help would be highly appreciated :((! Thanks.
To disallow users from clicking or selected a particular column, you will have to use custom table style for your data grid. In this custom table style you will have to add custom data column styles - DataGridTextBoxColumn. Derive a class from DataGridTextBoxColumn and in that override the Edit method and in that method do nothing. public class MyTextBoxColumn : DataGridTextBoxColumn { public MyTextBoxColumn() { // // TODO: Add constructor logic here // } protected override void Edit(...) { if (!ReadOnly) { base.Edit(..); // call base class } //don't call baseclass, so no editing.... } } This should take care of it! Hope this helps. Suhas
-
Hi, I want ComboBoxes displayed in all columns of datgrid, always visible. And there are a lot of things in DataGrid that are difficult to resolve. For ex, I always see one extra row at the bottom even when I have added the rows through DataTable and the DataTable.Row.Count is correct but Grid.VisibleRowCount is 1 greater. Also, I don't want the column with readonly=true to be selected, whereas when I click on that column the background of that row becomes gray ! Any help would be highly appreciated :((! Thanks.
To see ComboBox in DataGrid always - try to override Paint method in suhass'es example. To avoid extra row set DataGrid ListManager protected property: (DataView)(myDataGrid.ListManager.List).AllowNew=false; Hi, AW
-
To disallow users from clicking or selected a particular column, you will have to use custom table style for your data grid. In this custom table style you will have to add custom data column styles - DataGridTextBoxColumn. Derive a class from DataGridTextBoxColumn and in that override the Edit method and in that method do nothing. public class MyTextBoxColumn : DataGridTextBoxColumn { public MyTextBoxColumn() { // // TODO: Add constructor logic here // } protected override void Edit(...) { if (!ReadOnly) { base.Edit(..); // call base class } //don't call baseclass, so no editing.... } } This should take care of it! Hope this helps. Suhas
Hi Suhas, I tried what you said but it's not working the way I implemented it. I'll explain what I did. //Create a custom Column Style for the 1st Col: Questions CurrencyManager cm = (CurrencyManager)this.BindingContext[dtTable]; PropertyDescriptor pd = cm.GetItemProperties()[0];//Get Prop for the 1st col MyControls.MyDataGridTextBoxColumn myColStyle = new MyControls.MyDataGridTextBoxColumn(pd); newGrid[indexPage].TableStyles.Add(dgdtblStyle); newGrid[indexPage].TableStyles[0].GridColumnStyles.Add(myColStyle); And to create the MyControl Class: public class MyDataGridTextBoxColumn: DataGridTextBoxColumn { public MyDataGridTextBoxColumn(PropertyDescriptor pd) : base(pd) { } protected override void Edit(CurrencyManager cm, int rowNum, Rectangle bounds, bool readOnly) { MessageBox.Show("in Edit"); if (!readOnly) base.Edit(cm, rowNum, bounds, readOnly); } } But that MessageBox is bever clicked & nothing diff happens when I try to edit the 0th Col ! What do you think I am doing wrong ? Thanks. Paul
-
Hi Suhas, I tried what you said but it's not working the way I implemented it. I'll explain what I did. //Create a custom Column Style for the 1st Col: Questions CurrencyManager cm = (CurrencyManager)this.BindingContext[dtTable]; PropertyDescriptor pd = cm.GetItemProperties()[0];//Get Prop for the 1st col MyControls.MyDataGridTextBoxColumn myColStyle = new MyControls.MyDataGridTextBoxColumn(pd); newGrid[indexPage].TableStyles.Add(dgdtblStyle); newGrid[indexPage].TableStyles[0].GridColumnStyles.Add(myColStyle); And to create the MyControl Class: public class MyDataGridTextBoxColumn: DataGridTextBoxColumn { public MyDataGridTextBoxColumn(PropertyDescriptor pd) : base(pd) { } protected override void Edit(CurrencyManager cm, int rowNum, Rectangle bounds, bool readOnly) { MessageBox.Show("in Edit"); if (!readOnly) base.Edit(cm, rowNum, bounds, readOnly); } } But that MessageBox is bever clicked & nothing diff happens when I try to edit the 0th Col ! What do you think I am doing wrong ? Thanks. Paul
Hi, I put a label on top of that column in the data grid & now u cannot edit the text in that column. But if u click on any editable control like combo box in the datagrid, or even at any place in the grid where there are no rows, the first row gets selected ... What's happening !?! I was able to remove that extra row with AllowNew property set to false. Thanks for all ur help. But I think we need a much stronger DatagRid than what we have right now ! Paul
-
To see ComboBox in DataGrid always - try to override Paint method in suhass'es example. To avoid extra row set DataGrid ListManager protected property: (DataView)(myDataGrid.ListManager.List).AllowNew=false; Hi, AW
I was able to avoid that extra row the way you said. Is there a way to have Vertical Scrolling on in a DataGrid ? Thanks
-
Hi Suhas, I tried what you said but it's not working the way I implemented it. I'll explain what I did. //Create a custom Column Style for the 1st Col: Questions CurrencyManager cm = (CurrencyManager)this.BindingContext[dtTable]; PropertyDescriptor pd = cm.GetItemProperties()[0];//Get Prop for the 1st col MyControls.MyDataGridTextBoxColumn myColStyle = new MyControls.MyDataGridTextBoxColumn(pd); newGrid[indexPage].TableStyles.Add(dgdtblStyle); newGrid[indexPage].TableStyles[0].GridColumnStyles.Add(myColStyle); And to create the MyControl Class: public class MyDataGridTextBoxColumn: DataGridTextBoxColumn { public MyDataGridTextBoxColumn(PropertyDescriptor pd) : base(pd) { } protected override void Edit(CurrencyManager cm, int rowNum, Rectangle bounds, bool readOnly) { MessageBox.Show("in Edit"); if (!readOnly) base.Edit(cm, rowNum, bounds, readOnly); } } But that MessageBox is bever clicked & nothing diff happens when I try to edit the 0th Col ! What do you think I am doing wrong ? Thanks. Paul
pahluwalia@hotmail.com wrote: newGrid[indexPage].TableStyles.Add(dgdtblStyle); newGrid[indexPage].TableStyles[0].GridColumnStyles.Add(myColStyle); Add custom column styles to the custom table style AND then add the custom table style to the datagrid's table style collection. If you do the reverse, the way you have done, the data grid will not use your column styles