Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

The Schickster

The Schickster The Schickster

Niner since 2006

  • C++ and Beyond 2011: Herb Sutter - Why C++?

    Okay so I'm sitting here wondering, after having watched the video and having read most of the comments, why doesn't Microsoft rewrite all of those OS libraries that were written in managed code in C++? Why not write the .NET framework in C++ while keeping the APIs as they are? Then the only meta data that is needed is for the .NET app itself, not the entire framework.

    If you have developer productivity managed apps that are running as a thin layer on top highly optimized C++ doesn't everybody win? What am I missing?

  • A Quick Look At "Windows 8"

    @Justin:I can't help with your vertically aligned divs but here is the combobox Wink

     

    HTML:

    <div>
        <asp:TextBox safari:style="position:absolute; margin-top:0px;" style="position:absolute;" ID="txtDisplay" runat="server"></asp:TextBox>
        <asp:DropDownList ID="ddSelect" runat="server">
            <asp:ListItem Value="test1" >test1</asp:ListItem>
            <asp:ListItem Value="test2">test2</asp:ListItem>
        </asp:DropDownList>
    </div> 

    VB.NET

    Imports System.Collections
    Imports System.Collections.Generic
    
    Partial Class Controls_EditableDropdown
        Inherits System.Web.UI.UserControl
    
        Private _autoSort As Boolean = False
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            If Page.IsPostBack OrElse Page.IsCallback Then
                If txtDisplay.Text.Length > 0 Then
                    SyncItems()
                End If
            End If
    
            RegisterScripts()
            ddSelect.Attributes.Add("onChange", "try{" & Me.ClientID & "_DisplayText();}catch(ex){}")
    
        End Sub
    
        Public Overloads Sub DataBind(ByVal items As String())
            ddSelect.DataSource = items
            ddSelect.DataBind()
            If AutoSort Then
                SortDropDownList(ddSelect)
            End If
            If Not Page.IsPostBack AndAlso Not Page.IsCallback Then
                If ddSelect.Items.Count > 0 Then
                    ddSelect.SelectedIndex = 0
                    txtDisplay.Text = ddSelect.SelectedItem.Text
                End If
            End If
        End Sub
    
        Public Overloads Sub DataBind(ByVal dataTextField As String, ByVal dataValueField As String, ByVal dt As System.Data.DataTable)
            ddSelect.DataTextField = dataTextField
            ddSelect.DataValueField = dataValueField
            ddSelect.DataSource = dt
            ddSelect.DataBind()
            If AutoSort Then
                SortDropDownList(ddSelect)
            End If
            If Not Page.IsPostBack AndAlso Not Page.IsCallback Then
                If ddSelect.Items.Count > 0 Then
                    ddSelect.SelectedIndex = 0
                    txtDisplay.Text = ddSelect.SelectedItem.Text
                End If
            End If
        End Sub
    
        Public Property Width() As Unit
            Get
                Return ddSelect.Width
            End Get
            Set(ByVal value As Unit)
                ddSelect.Width = value
                ddSelect.Height = Unit.Pixel(22)
    
                If value.Value >= 24 Then
                    If Request.UserAgent.ToLower().Contains("webkit") Or Request.UserAgent.ToLower().Contains("firefox") Then
                        txtDisplay.Width = Unit.Pixel(value.Value - 22)
                    Else
                        txtDisplay.Width = Unit.Pixel(value.Value - 24)
                    End If
                End If
            End Set
        End Property
    
        Public ReadOnly Property Items() As ListItemCollection
            Get
                SyncItems()
                Return ddSelect.Items
            End Get
        End Property
    
        Public Property Text() As String
            Get
                Dim textValue As String = String.Empty
                If txtDisplay.Text.Length = 0 Then
                    If ddSelect.SelectedItem IsNot Nothing Then
                        textValue = ddSelect.SelectedItem.Text
                    End If
                Else
                    textValue = txtDisplay.Text
                End If
                Return textValue
            End Get
            Set(ByVal value As String)
                txtDisplay.Text = value
                SyncItems()
            End Set
        End Property
    
        Public ReadOnly Property Value() As String
            Get
                Dim ddValue As String = String.Empty
                If ddSelect.SelectedItem IsNot Nothing Then
                    ddValue = ddSelect.SelectedItem.Value
                Else
                    Dim item As ListItem = ddSelect.Items.FindByText(Text)
                    If item IsNot Nothing Then
                        ddValue = item.Value
                    End If
                End If
                Return ddValue
            End Get
        End Property
    
        Public ReadOnly Property TextControl() As TextBox
            Get
                Return txtDisplay
            End Get
        End Property
    
        Public ReadOnly Property DropDownControl() As DropDownList
            Get
                Return ddSelect
            End Get
        End Property
    
        Public Property AutoSort() As Boolean
            Get
                Return _autoSort
            End Get
            Set(ByVal value As Boolean)
                _autoSort = value
            End Set
        End Property
    
        Public Property DataSource() As Object
            Get
                Return ddSelect.DataSource
            End Get
            Set(ByVal value As Object)
                ddSelect.DataSource = value
            End Set
        End Property
    
        Public Sub Clear()
            ddSelect.Items.Clear()
            txtDisplay.Text = String.Empty
        End Sub
    
        Private Sub SyncItems()
            If txtDisplay.Text.Length > 0 Then
                AddItems()
                Dim item As ListItem = ddSelect.Items.FindByText(txtDisplay.Text.Trim())
                If ddSelect.SelectedItem IsNot Nothing Then
                    ddSelect.SelectedItem.Selected = False
                End If
                If item IsNot Nothing Then
                    item.Selected = True
                End If
            End If
        End Sub
    
        Private Sub AddItems()
            Dim existingItem As ListItem = ddSelect.Items.FindByText(txtDisplay.Text.Trim())
    
            If existingItem Is Nothing Then
                ddSelect.Items.Add(txtDisplay.Text.Trim())
            End If
    
            If AutoSort Then
                SortDropDownList(ddSelect)
            End If
    
        End Sub
    
        Private Sub RegisterScripts()
    
            Dim sb As New StringBuilder()
    
            If Not Page.ClientScript.IsStartupScriptRegistered("FindItem_function") Then
                With sb
                    .Append(vbCrLf).Append("function FindItem(opt){")
                    .Append(vbCrLf).Append("for (var i=0;i<opt.length;i++){")
                    .Append(vbCrLf).Append("if (opt[i].selected == true){")
                    .Append(vbCrLf).Append("return opt[i];")
                    .Append(vbCrLf).Append("break;")
                    .Append(vbCrLf).Append("}}")
                    .Append(vbCrLf).Append("}")
                    .Append(vbCrLf)
                End With
    
                Page.ClientScript.RegisterStartupScript(Me.GetType(), "FindItem_function", sb.ToString(), True)
            End If
    
            If Not Page.ClientScript.IsStartupScriptRegistered(Me.ClientID & "_DisplayText") Then
    
                sb.Length = 0
                With sb
                    .Append("function ").Append(Me.ClientID).Append("_DisplayText(){")
                    .Append(vbCrLf).Append("document.getElementById('").Append(txtDisplay.ClientID).Append("').value = ")
                    .Append(vbCrLf).Append("FindItem(document.getElementById('").Append(ddSelect.ClientID).Append("')).text;")
                    .Append(vbCrLf).Append("document.getElementById('").Append(txtDisplay.ClientID).Append("').focus();")
                    .Append(vbCrLf).Append("}")
                    .Append(vbCrLf)
    
                    .Append(vbCrLf).Append("function ").Append(Me.ClientID).Append("_getSelectedText(){")
                    .Append(vbCrLf).Append("return document.getElementById('").Append(txtDisplay.ClientID).Append("').value;")
                    .Append(vbCrLf).Append("}")
                    .Append(vbCrLf)
                End With
    
                Page.ClientScript.RegisterStartupScript(Me.GetType(), Me.ClientID & "_DisplayText", sb.ToString(), True)
    
            End If
    
        End Sub
    
        Public Shared Sub SortDropDownList(ByVal ddl As DropDownList)
    
            Dim arl As ArrayList = Nothing
            Dim inited As Boolean = False
            If (ddl.Items.Count > 0) Then
                arl = New ArrayList(ddl.Items.Count)
                For Each li As ListItem In ddl.Items
                    arl.Add(li)
                    inited = True
                Next
            End If
    
            If inited Then
                arl.Sort(New ListItemComparer)
                ddl.Items.Clear()
                For Each l As ListItem In arl
                    ddl.Items.Add(l)
                Next
            End If
    
        End Sub
    
        Private Class ListItemComparer
            Implements IComparer
    
            Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
                Dim li_x As ListItem = CType(x, ListItem)
                Dim li_y As ListItem = CType(y, ListItem)
                Dim c As CaseInsensitiveComparer = New CaseInsensitiveComparer
    
                Return c.Compare(li_x.Text, li_y.Text)
    
            End Function
    
        End Class
    
    End Class
    

     

    Cheer up everyone. I'm sure new tools will come out to make this new strange world easier and more powerful than you can currently imagine.

  • Windows Workflow Foundation API Usability Lab Video – Part 2

    Very interesting to watch.  I recently watched another video about using Predictive Fetch with Ajax in web forms and watching this video brought it to mind.

    I think Microsoft could go a long way into enhancing the intellisense with predictive fetch and it sure would have helped in this case.

    Another observation I made was when the poor guy had to search through the documentation as we all have done, and there is just this overwhelming amount of data to parse.  Maybe MS can use the predictive fetch to draw an order of probability for what the user is looking for based upon the subjects he has highlighted in the search results pane!  Now that would be the next level of intelligent programming!Smiley