Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid Scrollbar does not get enabled

Status
Not open for further replies.

mthakershi

Programmer
Aug 24, 2001
79
US
I am using a Datagrid control in a C# windows application. I don't know why but the scrollbars (vertical and horizontal) won't get enabled even though there are many rows and columns to scroll. It stays visible though. I have to manually enable the scrollbars by resizing or sorting any of the columns.

I have already tried changing width and triggering sort from code but it does not work.

Thanks,
Malay Thakershi
 
Is the datagrid set to ReadOnly = True? If it is, that would explain it.
 
Well, ReadOnly is true but it should still let me scroll the grid. This happens only with few grids and not all. I also tried with ReadOnly = False, still it does the same.

Malay
 
Are you able to click in the grid and edit the data?
 
No. When I style my grid, I explicitly lock columns. I don't want users to edit data in this grid. Let me show you how I assign properties to the columns.

dataGridTextBoxColumn1.Format = "";
dataGridTextBoxColumn1.FormatInfo = null;
dataGridTextBoxColumn1.HeaderText = "Procedure Code";
dataGridTextBoxColumn1.MappingName = "CPT";
dataGridTextBoxColumn1.NullText = "";
dataGridTextBoxColumn1.ReadOnly = true;
dataGridTextBoxColumn1.Width = 110;
dataGridTextBoxColumn1.TextBox.Enabled = false;

I really don't think readonly has anything to do with this issue, but anything is possible.

Malay
 
Malay

Yeah, I think your right, the ReadOnly property probably doesn't matter here.

Sorry, but I have to ask the question... is the Enable property of the grid set to True?; or do you maybe have other control disabling code in your module that might unknowingly be targeting your grid?
 
Hey cmn2,

Yes. Enabled property of the grid as well as of all its parents at any level is true.

See, the scenario is something like this:

When the form loads, the group box/frame that has the grid is disabled, as no entity is selected. Then user selects an entity for which he/she wants to see details and I enable the frame and grid with data in it.

Thanks for taking interest in the thread.

Malay
 
Malay
I'm running low on ideas here, but here is one.
If at first your grid was not part of your groupbox and then you cut and pasted it there, your code may not be handling the control events as you intended. I have had problems doing just this sort of thing in the past. I find it best to start a fresh instance of a container such as a panel(groupbox in your case), add new instances of controls to the container and then fresh code those controls. Working backwards trying to hook controls to existing code always seems to create problems.
I don't know if the grid in the groupbox was the result of a cut and paste, but if it was you may want to start with some new instances. You may also want to give some thought to using a panel instead of a groupbox.
 
Hi,

I just fixed this. This is a weird kind of bug in datagrid. You would expect scrollbars to get enabled when you enable the datagrid and there is a need of scrolling as they are internal to the datagrid. So what you have to do is traverse the controls collection of the datagrid and if scrollbar type of control is found, enable it.

Here are the functions I used.

public static void mfpEnableDataGrid(DataGrid aObjGrid)
{
try
{
aObjGrid.Enabled = true;
mfpEnableHScrollBar(aObjGrid);
mfpEnableVScrollBar(aObjGrid);
}
catch(Exception ex)
{
Console.WriteLine("Exception: " + ex.Message.ToString());
throw;
}
finally
{
}
}



public static void mfpEnableHScrollBar(Control aObjControl)
{
try
{
foreach (Control pObjC in aObjControl.Controls)
{
if(pObjC.GetType().ToString().ToUpper().Equals("SYSTEM.WINDOWS.FORMS.HSCROLLBAR"))
{
pObjC.Enabled = true;
return;
}
}
}
catch(Exception ex)
{
Console.WriteLine("Exception: " + ex.Message.ToString());
throw;
}
finally
{
}
}

public static void mfpEnableVScrollBar(Control aObjControl)
{
try
{
foreach (Control pObjC in aObjControl.Controls)
{
if(pObjC.GetType().BaseType.ToString().ToUpper().Equals("SYSTEM.WINDOWS.FORMS.VSCROLLBAR"))
{
pObjC.Enabled = true;
return;
}
}
}
catch(Exception ex)
{
Console.WriteLine("Exception: " + ex.Message.ToString());
throw;
}
finally
{
}
}


Thanks cmn2.

Thanks,
Malay
 
Good find. Ironicly enough, I just ran into this same fix this morning while doing something unrelated. But it looks like you got it working :)

-Rick

----------------------
 
Malay

I'm glad you figured this out. Believe it or not, shortly after my last reply I started having a similar problem with my datagrid scrollbars. The visible property seemed to trigger it. If I went from visible = true to visible = false and then back to true it killed my scrollbars. Anyway, its good we're all back in business.

I hope Microsoft is reading this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top