I have a custom combobox as below

public class ListViewCombo : ComboBox
{   
    ToolStripControlHost listViewHost;
    ToolStripDropDown dropDown;
    public ListViewCombo()
    {
        ListView lstView = new ListView();
        lstView.BorderStyle = BorderStyle.None;
        listViewHost = new ToolStripControlHost(lstView);
        dropDown = new ToolStripDropDown();
        dropDown.Items.Add(listViewHost);
    }

    public ListView TListView
    {
        get { return listViewHost.Control as ListView; }
    }

    private void ShowDropDown()
    {
        if (dropDown != null)
        {
            listViewHost.Width = DropDownWidth;
            listViewHost.Height = DropDownHeight;
            dropDown.Show(this,new Point(this.Loation.X, this.Height),ToolStripDropDownDirection.BelowRight);
        }
    }

    private const int WM_USER = 0x0400,
                      WM_REFLECT = WM_USER + 0x1C00,
                      WM_COMMAND = 0x0111,
                      CBN_DROPDOWN = 7;

    public static int HIWORD(int n)
    {
        return (n >> 16) & 0xffff;
    }

    protected override void WndProc(ref Message m)
    {
        if (m.Msg == (WM_REFLECT + WM_COMMAND))
        {
            if (HIWORD((int)m.WParam) == CBN_DROPDOWN)
            {
                ShowDropDown();
                return;
            }
        }
        base.WndProc(ref m);
    }

    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {
            if (dropDown != null)
            {
                dropDown.Dispose();
                dropDown = null;
            }
        }
        base.Dispose(disposing);
    }
  }
 }

Every thing is good except when I move the form towards right or left of the screen to partially hide the custom combobox and clicks the dropdown button, then the dropdown automatically adjusts the location and fully displayed. That is even if the combobox is not displayed completely in the screen, the dropdownlist completely displayed by adjusting its position.

Is the ToolStripDropDown has no bounds constrain?.

I have hosted my custom combobox (ComboBoxEx) on datagridview by following the steps in http://msdn.microsoft.com/en-us/library/7tas5c80.aspx.

  1. I have created DataGridVIewComboExColumn derrived from DataGridViewColumn
  2. Custom cell named "DataGridVIewComboExCell" is created from DataGridViewCell
  3. Finally my custom edit control "ComboExEditCtrl" (derived from ComboBoxEx and implements IDataGridViewEditingControl) is created.
  4. In ComboExEditCtrl, OnSelectedValueChanged method is overrided as below.

    protected override void OnSelectedValueChanged(EventArgs eventargs)
    {
        // Notify the DataGridView that the contents of the cell 
        // have changed.
        valueChanged = true;
        this.EditingControlDataGridView.NotifyCurrentCellDirty(true);
        base.OnSelectedValueChanged(eventargs);
    }

    Whenever the grid is loaded, custom control (ComboExEditCtrl) displayed on the cell. The problem is when I change the value on custom control (ComboExEditCtrl) and click on the next cell the custom control disappears. Also when i click back on the same cell (custom control cell) in the datagridview the custom control appears.

I have followed almost the same steps described in MSDN (above link). I dont know what I am missing. Please help

How to shrink the client area of a multiline textbox (Windows.Forms.Textbox) from the non-client area?

That is I need to draw a focus line in-between verticalscrollbar and the text area of textbox (i.e line to be drawn inside textbox). So I need a space between the client area (typable area) and the scrollbar to draw the line. Any idea how to achieve this?

The column resize issue is solved by manually calculating the columnwidth(iterating through each column content to find the largest one) in the columnDivider double click event.

stringFormat.FormatFlags=(StringFormatFlags.NoWrap & StringFormatFlags.NoClip).

I tried this. But no use.

Thank you tinstaafl for the replay.

In my ownerdrawn listview, I had overrided the OnDrawSubItem() method to draw the text. The text is drawn as below.

e.SubItem.Font=customFont
stringFormat.Trimming=StringTrimming.EllipsCharacter
stringFormat.FormatFlags=StringFormatFlags.NoWrap
e.Graphics.DrawString(string,customFont,brush,e.Bounds,stringFormat)

In the double-click event, column width is setted to -1. When the column divider is double clicked, the column is resized according to the size of customFont. But still the text is not displayed completely. Is there any problem with the StringFormat?

When I change the draw string method as below
e.Graphics.DrawString(string,customFont,brush,e.Bounds.X,e.Bounds.Y)
and double-clicks the column divider, the column will be resized to show the text completely. Here I cann't set the string format to display the ellipses. So I cannot use this method.

(1) Any Idea? What should I do to display the whole text completely? Does I am missing any thing in the DrawString() ?

(2)In ListBox we have "LB_ADDSTRING" message which is posted when any item is added to the ListBox. In the ListView is there any equalent messages which is raised when any items are added, deleted or updated?

When the ListVIew column width=-1, the column will be resized to fit its column contents. How does the length or size is calculated by the listview? Is there any windows message to get thelongest content in the listview? Any idea...?

I have my own ListView class, inheriting from Forms.ListView. When double clicking on the column divider, the columns resize to show the column items in full size.

However, for me this doesnt work properly - some words are partially hidden because I am using large font size to draw items.

Now, when the column is double clicked, I want to calculate the column size by measuering the size of largest string in the column. Any one know how to find the largest string in the listview column without iterating each item in the listview?

Thank you TnTinMN. I will look into it.

I am using LIstView control in virtual mode with the property listView.VirtualMode=True and I have subscribed the event listView1_RetrieveVirtualItem(). But this event is being called many times for each item. What is the reason or How can I prevent RetrieveVirtualItem() from executing many times?
Please check the below code.

public class Form1 : Form
{
    public Form1()
    {
        listView1.VirtualMode = true;
        listView1.VirtualListSize = 100000;

        listView1.RetrieveVirtualItem += new RetrieveVirtualItemEventHandler(listView1_RetrieveVirtualItem);

    }

    private void listView1_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
    {
            ListViewItem itm=new ListViewItem(comboBOx.Items[e.ItemIndex].ToString());
            e.Item = itm;

        // For each visibile item this code is executed many time.
    }    
}

Sorry I cann't. It should be in Winforms, that is the requirement. BY the way I have worked on it and I just replaced the combobox list control with my custom listbox control. So if the user click the combobox button, my custom listcontrol will be shown. It works fine. But the problem is that when the combobox style is set to "DropDownList" and when the user select an item from the listcontrol it is not displayed on the text area of combobox. How can I draw the selected text to the combobox?

I have skinned most controls in my winform application, except scrollbar in combobox. Any ideas?

The problem is solved. I have masked the original scrollbar of textbox by my customized scrollbar. GetScrollInfo API is used to synch the scrollbars.

I have created a control by placing a text box and a vertical scroll bar. When I scroll the scroll bar, the contents in the text box should be scrolled. How can I scroll the text box by scrolling my standalone scroll bar?
Please check the below sample code.

public partial class EditControl : Control
{
    int BORDERWIDTH = SystemInformation.Border3DSize.Width;
    int SCROLLBARWIDTH = SystemInformation.VerticalScrollBarWidth;
    CustomTextBox editCtrl;
    VScrollBar vScrollBar = null;
    public EditControl()
    {
        InitializeComponent();
        editCtrl = new CustomTextBox();
        this.Width = 200 + SCROLLBARWIDTH;
        this.Height = 140;

        editCtrl.Width = this.Width - SCROLLBARWIDTH;
        editCtrl.Height = this.Height;
        editCtrl.Multiline = true;
        editCtrl.Left = Left;

        vScrollBar = new VScrollBar();
        vScrollBar.Height = this.Height;
        vScrollBar.Location = new Point(editCtrl.Width, 1);
        vScrollBar.Scroll += new ScrollEventHandler(vScrollBar_Scroll);
        this.Controls.Add(editCtrl);
        this.Controls.Add(vScrollBar);
    }

    private void vScrollBar_Scroll(object sender, ScrollEventArgs e)
    {
        **//Code to scroll the text box
        //editCtrl.ScrollTo(position);**
    }
    protected override void OnResize(EventArgs e)
    {
        base.OnResize(e);
        editCtrl.Width = this.Width - SCROLLBARWIDTH;
        editCtrl.Height = this.Height;
    }
    public partial class CustomTextBox : TextBox
    {
        public CustomTextBox()
        {
            //InitializeComponent();
        }
        public void ScrollTo(int Position)
        {
           **//Code to scroll the contents.**
        } 
    }
}
}

In my project, I need a stand alone scroll bar for my text box. So I have created a customized scroll bar. Any idea How to use my customized scroll bar(both Horizontal and Vertical) in the text box instead of built-in scroll bar?

You can draw a border by setting the SmoothingMode as AntiAlias.

    // Set the SmoothingMode property to smooth the line.
    e.Graphics.SmoothingMode = 
        System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

Finally I got the object which causes the leak!! Thanks to Bear(http://thesz.diecru.eu/content/bear.php). The Font object in some custom controls are not get disposed even if the control's Dispose() method is called. The GDI object(Font) count keeps increasing with 1. Anyone know, why the Font is not disposing properly. How can I dispose the font object when destroying the control?

Opening and closing form simple keeps an increase in GDI object count in the Task Manager.
In the code I am disposing all objects like Pen,Brush, Region, Bitmaps etc. But there is an increase in the GDI count. How do I find which Object causes the leak?

In my project, I have created around 12 custom controls(checkbox,radiobutton,editbox,progressbar,scrollbar,button etc...). Custom painting is done in all controls for the extended look and feel using Pen,Brushes,Graphics, GraphicPath,Images,Region and Bitmaps ect. After the use of these objects, I have disposed the objects using the Dispose() method. I am using these controls in a System.Windows Form. When I am contiously showing and closing the Form causes an increase in the GDI objecs each time. I have checked the GDI object count using Task Manager and confirmed the GDI leak in the form.
My question is, how can I manage this GDI leak?
How do I find which GDI object causes the leak eventhough I am disposing the GDI objects?

Thank you.

Hi All,

Is there any event to catch the column visibility change of datagridview?

I am using a custom datagridview. I need to update the horizontal scrollbar maximum value whenever the column visibility is changed.

Please provide some idea.
Thank you.

Hi All,
I had solved it.

The editbox of combobox was replaced with a rich text box when the style is "DropDown". While disabling the control, the rich textbox will be displayed as white color.

I solved it by hiding the rich textbox.

Thank you...

Hi,

I have a custom combobox(say comboboxEX) derived from System.Windows.Forms.ComboBox.
OnPaint() event I have some background color and styles for the combobox. Every thing works fine.

My problem is, I can't set background color when DropDownStyle is "DropDown" and Enabled = false.
But it workes when DropDownStyle is "DropDownList" and Enabled = false.

How do I set background color for "DropDown" when it is in disabled state?
Any help will be appreciated.

[QUOTE=RamyMahrous;598082]I've searched how can you detect your speed and I got this piece of code
[code=c#]
System.Net.WebClient wc = new System.Net.WebClient();
DateTime dt1 = DateTime.Now;
byte[] data = wc.DownloadData("http://google.com");
DateTime dt2 = DateTime.Now;
return (data.Length * 8) / (dt2 - dt1).TotalSeconds;
[/code][/QUOTE]

Thanks .Its a good idea.

Hi, all

   I am downloading a file using webclient class in C#. Can I calculate the downloading  speed using any custom PerformanceCounter.Can any one help me.

Thanks in advance..

[QUOTE=majestic0110;597065]Hi, this may help you:

Please do not ask me to explain I have had very little experience with this myself lol[/QUOTE]

Hi, Thanks.
I have reffered the same .but how can I use the structure in my application.Do i import any APIs?

Hi all.
I am new in C#. How can i use NETCONNECTINFOSTRUCT Structure.Wht r the related APIs.
Can any one help me?

Thanks in advance.........

hi all,

  How can i zip and unzip a file using SharpZipLib. I am wrking in C#.

Can any one help me?
Thanks in Advance

hi all..
how can i zip and unzip a file using SharpzipLib.Dll.
Can any one help me?.
Thanks in advance...

hi thanks.....its good idea.